bumpsoo 2024-12-02 21:29:00 +09:00
parent 6a2a68ee17
commit 633fef64b3

View file

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