diff --git a/Palindrome partitioning.py b/Palindrome partitioning.py new file mode 100644 index 00000000..d187b61a --- /dev/null +++ b/Palindrome partitioning.py @@ -0,0 +1,31 @@ +class Solution: + def partition(self, s: str) -> List[List[str]]: + self.result=[] + self.helper(s,0,[]) + return self.result + + def helper(self,s,pivot,path): + #base case + if pivot==len(s): + self.result.append(path[:]) #copy + return + for i in range(pivot,len(s)): + curr_str=s[pivot:i+1] + if self.isPalindrome(curr_str): + #action + path.append(curr_str) + #recurse + self.helper(s,i+1,path) + #backtrack + path.pop() + + def isPalindrome(self,s): + l=0 + h=len(s)-1 + + while l List[List[int]]: + self.result=[] + self.helper(nums,0,[]) + return self.result + + def helper(self,nums,i,path): + #base + if i==len(nums): + self.result.append(path) + return + + #nochoose + self.helper(nums,i+1,path) + #choose + self.helper(nums,i+1,path+[nums[i]]) \ No newline at end of file