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

Обновлено: 2024-03-12
1 мин
[]

Содержание

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