Created
May 15, 2020 11:13
-
-
Save coldmanck/7c9e40cd60632b73b9338967d80c7973 to your computer and use it in GitHub Desktop.
LeetCode 0063 combination sum (Backtrack)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | |
ans.append(cur_ans) | |
return | |
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