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
'IT > 코딩테스트' 카테고리의 다른 글
[Leetcode] 404. Sum of Left Leaves (0) | 2024.04.14 |
---|---|
[Leetcode] 3114. Latest Time You Can Obtain After Replacing Characters (0) | 2024.04.14 |
[Leetcode] 3110. Score of a String (0) | 2024.04.13 |
[Leetcode] 2073. Time Needed to Buy Tickets (0) | 2024.04.09 |
[Leetcode] 1700. Number of Students Unable to Eat Lunch (0) | 2024.04.08 |