본문 바로가기

IT/코딩테스트

[Leetcode] 2000. Reverse Prefix of Word

728x90

https://leetcode.com/problems/reverse-prefix-of-word

class Solution:
    def reversePrefix(self, word: str, ch: str) -> str:
        index = word.find(ch)
        if index == -1:
            return word

        return word[index::-1] + word[index+1:]
728x90