https://github.com/w5678/leetcode-2021
https://github.com/w5678/leetcode-2021力扣

class Solution:
def reversePrefix(self, word: str, ch: str) -> str:
idx = word.find(ch)
return word if idx== -1 else word[0:idx+1][::-1]+ word[idx+1:]
真的是练语法的
该博客介绍了一个Python实现的LeetCode问题解决方案,即找到并反转字符串中指定字符的前缀。类方法`reversePrefix`接收一个字符串`word`和一个字符`ch`,如果`ch`在`word`中,它会返回`ch`及其前面部分的反转,否则返回原字符串。
406

被折叠的 条评论
为什么被折叠?



