Reverse Prefix of Word (Leetcode 2000)

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

class Solution:
    def reversePrefix(self, word: str, ch: str) -> str:
        
        for i in range(len(word)):
            if(word[i]==ch):
                break
        else:
            return word
        s=word[:i+1][::-1]+word[i+1:]
        return s

Last updated