java: add «1455. Check If a Word Occurs As a Prefix of Any Word in a Sentence»
URL: https://leetcode.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence/ Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
b2a1f19ea6
commit
6522258548
1 changed files with 12 additions and 0 deletions
|
@ -0,0 +1,12 @@
|
||||||
|
class Solution {
|
||||||
|
public int isPrefixOfWord(String sentence, String searchWord) {
|
||||||
|
var words = sentence.split(" ");
|
||||||
|
for (int i = 0; i < words.length; ++i) {
|
||||||
|
if (words[i].startsWith(searchWord)) {
|
||||||
|
return 1 + i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue