super easy python backtracking recursive solution


  • 0
    G
    class Solution(object):
        def isPalindromic(self, s):
            size = len(s)
            start = 0
            end = size - 1
            
            while start < end:
                if s[start] != s[end]:
                    return False
                start += 1
                end -= 1
            return True
        
        def partition(self, s):
    
            if not s:
                return [[]]
            
            size = len(s)
            ans = []
            
            for index in range(1,size+1):
                substr = s[:index]
                if self.isPalindromic(substr):
                    for p in self.partition(s[index:]):
                        ans.append([substr] + p)
            
            return ans
                
                
                
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.