Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
LeetCode 0063 combination sum (Backtrack)
def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:
def combination_sum(cur_ans, cur_sum, cand_idx):
if cur_sum >= target:
if cur_sum == target:
for i in range(cand_idx, len(candidates)):
combination_sum(cur_ans + [candidates[i]], cur_sum + candidates[i], i)
ans = []
combination_sum([], 0, 0)
return ans
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment