2000. Reverse Prefix of Word

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

On This Page

LeetCode problem 2000

class Solution:
    def reversePrefix(self, word: str, ch: str) -> str:
        i = word.find(ch)
        return word if i == -1 else word[i::-1] + word[i + 1 :]