131. Palindrome Partitioning

class Solution:
    def partition(self, s: str) -> List[List[str]]:
        def checkPalindrome(word):
            return word == word[::-1]

        ans = []
        def backtrack(index, prev, temp):
            nonlocal ans
            if index >= len(s):
                if checkPalindrome(prev):    
                    ans.append(temp + [prev])                        
                return

            if checkPalindrome(prev):
                backtrack(index + 1, s[index], temp + [prev]) 

            backtrack(index + 1, prev + s[index], temp)

        backtrack(1, s[0], [])
        return ans