본문 바로가기
python-algorithm

leetcode 2000. Reverse Prefix of Word

by 무적김두칠 2024. 5. 2.

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

 

1
2
3
4
5
6
7
class Solution:
    def reversePrefix(self, word: str, ch: str-> str:
        if word.find(ch) == -1:
            return word
        else:
            return word[:word.find(ch)+1][::-1+ word[word.find(ch)+1:]
        
cs
반응형

댓글