2024-12-11 17:31:43 +08:00

12 lines
288 B
Python

import re
class Solution:
def reversePrefix(self, word: str, ch: str) -> str:
match = re.search(rf"{ch}", word)
if match:
position = match.start()
return word[: position + 1][::-1] + word[position + 1 :]
else:
return word