This commit is contained in:
parent
6a2a68ee17
commit
633fef64b3
1 changed files with 12 additions and 0 deletions
|
|
@ -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
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue