From 084c25955a06fc6ca228d25954f9049d4ac824a6 Mon Sep 17 00:00:00 2001 From: Yash Agrawal Date: Sat, 11 Apr 2026 21:02:19 +0530 Subject: [PATCH 1/2] closes #43 and #25: Add Python solution for Combination Sum - Leetcode 39 --- .../Combination Sum - Leetcode 39.py | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Combination Sum - Leetcode 39/Combination Sum - Leetcode 39.py b/Combination Sum - Leetcode 39/Combination Sum - Leetcode 39.py index e69de29..9f9a6a1 100644 --- a/Combination Sum - Leetcode 39/Combination Sum - Leetcode 39.py +++ b/Combination Sum - Leetcode 39/Combination Sum - Leetcode 39.py @@ -0,0 +1,21 @@ +class Solution: + def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]: + res = [] + sol = [] + + def backtrack(i, cur_sum): + if cur_sum == target: + res.append(sol.copy()) + return + + if cur_sum > target or i == len(candidates): + return + + backtrack(i + 1, cur_sum) + + sol.append(candidates[i]) + backtrack(i, cur_sum + candidates[i]) + sol.pop() + + backtrack(0, 0) + return res \ No newline at end of file From 4719e6de1bbab29d06d43256346e62f28ede1925 Mon Sep 17 00:00:00 2001 From: Yash Agrawal Date: Sat, 11 Apr 2026 21:05:23 +0530 Subject: [PATCH 2/2] closes #43 and #25: Add Python solution for Combination Sum - Leetcode 39 --- .../Combination Sum - Leetcode 39.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Combination Sum - Leetcode 39/Combination Sum - Leetcode 39.py b/Combination Sum - Leetcode 39/Combination Sum - Leetcode 39.py index 9f9a6a1..2a1ac85 100644 --- a/Combination Sum - Leetcode 39/Combination Sum - Leetcode 39.py +++ b/Combination Sum - Leetcode 39/Combination Sum - Leetcode 39.py @@ -18,4 +18,7 @@ def backtrack(i, cur_sum): sol.pop() backtrack(0, 0) - return res \ No newline at end of file + return res + +# Time Complexity: O(2^target) +# Space Complexity: O(target) \ No newline at end of file