1455. Check If a Word Occurs As a Prefix of Any Word in a Sentence

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1455

class Solution:
    def isPrefixOfWord(self, sentence: str, searchWord: str) -> int:
        for i, s in enumerate(sentence.split(), 1):
            if s.startswith(searchWord):
                return i
        return -1