HTMLify
LeetCode - Check If a Word Occurs As a Prefix of Any Word in a Sentence - Python
Views: 209 | Author: abh
class Solution:
def isPrefixOfWord(self, sentence: str, searchWord: str) -> int:
for word in sentence.split(" "):
if word.startswith(searchWord):
return sentence.split(" ").index(word) + 1
return -1