From 31fb2d0629a3ff8c1ddbd8af952b186900c9853e Mon Sep 17 00:00:00 2001 From: Shakthi Nandana Date: Wed, 13 May 2026 22:21:56 -0400 Subject: [PATCH] solutions --- palindrome-partitioning.py | 36 ++++++++++++++++++++++++++++++++++++ subsets.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 palindrome-partitioning.py create mode 100644 subsets.py diff --git a/palindrome-partitioning.py b/palindrome-partitioning.py new file mode 100644 index 00000000..d54300e4 --- /dev/null +++ b/palindrome-partitioning.py @@ -0,0 +1,36 @@ +# Time Complexity: O(N*z^N) +# Space Complexity: O(N) +# Did this code successfully run on Leetcode : Yes + +class Solution(object): + def ispal(self,s): + if s==s[::-1]: + return True + return False + + def partition(self, s): + """ + :type s: str + :rtype: List[List[str]] + """ + + res=[] + path=[] + + def helper(pivot): + if pivot == len(s): + res.append(list(path)) + return + + for i in range(pivot, len(s)): + sub_str=s[pivot:i+1] + if self.ispal(sub_str): + path.append(sub_str) + helper(i+1) + path.pop() + + helper(0) + return res + + + \ No newline at end of file diff --git a/subsets.py b/subsets.py new file mode 100644 index 00000000..e0f0a2a4 --- /dev/null +++ b/subsets.py @@ -0,0 +1,29 @@ +# Time Complexity: O(N*2^N) +# Space Complexity: O(N) +# Did this code successfully run on Leetcode : Yes + +class Solution(object): + def subsets(self, nums): + """ + :type nums: List[int] + :rtype: List[List[int]] + """ + res=[] + path=[] + + def helper(idx): + #base + if idx==len(nums): + res.append(path[:]) + return + + #logic + helper(idx+1) + + path.append(nums[idx]) + helper(idx+1) + path.pop() + + helper(0) + return res +