diff --git a/easy/check_if_a_word_occurs_as_a_prefix_of_any_word_in_a_sentence.py b/easy/check_if_a_word_occurs_as_a_prefix_of_any_word_in_a_sentence.py new file mode 100644 index 0000000..6032723 --- /dev/null +++ b/easy/check_if_a_word_occurs_as_a_prefix_of_any_word_in_a_sentence.py @@ -0,0 +1,12 @@ +# https://leetcode.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence + +class Solution: + def isPrefixOfWord(self, sentence: str, searchWord: str) -> int: + words = sentence.split(' ') + length = len(searchWord) + + for i in range(len(words)): + if searchWord == words[i][0:length]: + return i + 1 + return -1 +