From 57b8cc76d7ce6d970b6f7753c0a9338305808aeb Mon Sep 17 00:00:00 2001 From: Y SrinivasaSupreeth Date: Wed, 28 Jan 2026 18:51:03 +0530 Subject: [PATCH] My_solution --- leetcode_131.py | 21 +++++++++++++++++++++ leetcode_78.py | 6 ++++++ 2 files changed, 27 insertions(+) create mode 100644 leetcode_131.py create mode 100644 leetcode_78.py diff --git a/leetcode_131.py b/leetcode_131.py new file mode 100644 index 00000000..08337471 --- /dev/null +++ b/leetcode_131.py @@ -0,0 +1,21 @@ +class Solution: + def partition(self, s: str) -> List[List[str]]: + res = [] + + def is_palindrome(sub): + return sub == sub[::-1] + + def dfs(start, path): + if start == len(s): + res.append(path[:]) + return + + for end in range(start + 1, len(s) + 1): + sub = s[start:end] + if is_palindrome(sub): + path.append(sub) + dfs(end, path) + path.pop() # backtrack + + dfs(0, []) + return res \ No newline at end of file diff --git a/leetcode_78.py b/leetcode_78.py new file mode 100644 index 00000000..957c4a46 --- /dev/null +++ b/leetcode_78.py @@ -0,0 +1,6 @@ +class Solution: + def subsets(self, nums: List[int]) -> List[List[int]]: + res = [[]] + for x in nums: + res += [r + [x] for r in res] + return res