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:
Matej Focko 2024-12-02 23:09:47 +01:00
parent b2a1f19ea6
commit 6522258548
Signed by: mfocko
SSH key fingerprint: SHA256:icm0fIOSJUpy5+1x23sfr+hLtF9UhY8VpMC7H4WFJP8

View file

@ -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;
}
}