class Solution:
def reversePrefix(self, word: str, ch: str) -> str:
i = word.find(ch) + 1
return word[:i][::-1] + word[i:]
# 作者:LeetCode-Solution
# 链接:https://leetcode-cn.com/problems/reverse-prefix-of-word/solution/fan-zhuan-dan-ci-qian-zhui-by-leetcode-s-ruaj/
class Solution:
def isPrefixOfWord(self, sentence: str, searchWord: str) -> int:
if not sentence:
return -1
sentence=sentence.strip().split()
for i in range(len(sentence)):
a=sentence[i]
if searchWord==a[:len(searchWord)]:
return i+1
return -1
# 作者:Jamiechen_sjtu
# 链接:https://leetcode-cn.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence/solution/yi-ci-bian-li-qing-song-gao-ding-by-jamiechen_sj-3/