0
点赞
收藏
分享

微信扫一扫

DAY18-T2000&T1455 -2022-02-02-非自己作答

小桥流水2016 2022-02-02 阅读 25
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/
举报

相关推荐

0 条评论