Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions problem1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# problem 1
# https://leetcode.com/problems/subsets/

class Solution:
def subsets(self, nums: List[int]) -> List[List[int]]:
self.final_arr = []
self.nums = nums
self.path = []
self.helper(0)
return self.final_arr


def helper(self,i):
if i == len(self.nums):
self.final_arr.append(self.path.copy())
return
self.helper(i+1)
self.path.append(self.nums[i])
self.helper(i+1)
self.path.pop()
29 changes: 29 additions & 0 deletions problem2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# problem 2

# https://leetcode.com/problems/palindrome-partitioning/
class Solution:
def partition(self, s: str) -> List[List[str]]:
self.final_arr = []
self.helper(s,0,[])
return self.final_arr

def helper(self,s,pivot,path):
if pivot == len(s):
self.final_arr.append(list(path))
return
for i in range(pivot,len(s)):
sub_str = s[pivot:i+1]
if self.isPalindrome(sub_str):
path.append(sub_str)
self.helper(s,i+1,path)
path.pop()

def isPalindrome(self,ip_str):
i = 0
j = len(ip_str)-1
while(i<j):
if ip_str[i] != ip_str[j]:
return False
i+=1
j-=1
return True