본문 바로가기
python-algorithm

leetcode 2000. Reverse Prefix of Word

by 무적김두칠 2022. 3. 16.

1
2
3
4
5
6
7
8
9
class Solution:
    def reversePrefix(self, word: str, ch: str-> str:
        try:
            that=word.index(ch)
            word=word[:that+1][::-1]+word[word.index(ch)+1:]
            #return newWord
        except : #return word 
            pass
        return word
cs
반응형

댓글