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 |
반응형
'python-algorithm' 카테고리의 다른 글
leetcode 2185. Counting Words With a Given Prefix (0) | 2022.03.17 |
---|---|
leetcode 557. Reverse Words in a String III (0) | 2022.03.17 |
leetcode 1704. Determine if String Halves Are Alike (0) | 2022.03.16 |
leetcode 1464. Maximum Product of Two Elements in an Array (0) | 2022.03.16 |
leetcode 125. Valid Palindrome (0) | 2022.03.15 |
댓글