Check If a Word Occurs As a Prefix of Any Word in a Sentence LeetCode solution in Python

1
class Solution(object):
2
def isPrefixOfWord(self, sentence, searchWord):
3
"""
4
:type sentence: str
5
:type searchWord: str
6
:rtype: int
7
"""
8
word_list = sentence.split()
9
counter = 0
10
for word in sentence.split():
11
counter += 1
12
if searchWord == word[0 : len(searchWord)]:
13
return counter
14
return -1

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0