From d57293608a10de4f87562ec17b40a3ff023b1ec9 Mon Sep 17 00:00:00 2001 From: BharathVuppala96 Date: Mon, 2 Feb 2026 12:05:49 -0800 Subject: [PATCH] 1 problem completed --- combination sum.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 combination sum.py diff --git a/combination sum.py b/combination sum.py new file mode 100644 index 00000000..a2964256 --- /dev/null +++ b/combination sum.py @@ -0,0 +1,21 @@ +class Solution: + def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]: + self.result=[] + self.helper(candidates,target,0,[]) + return self.result + def helper(self,candidates,target,i,path): + + #basecase + if target<0 or i==len(candidates): + return + if target==0: + self.result.append(path) + return + + #nochoose case + self.helper(candidates,target,i+1,list(path)) + #choose case + path.append(candidates[i]) + self.helper(candidates,target-candidates[i],i,list(path)) + + \ No newline at end of file