Created
May 15, 2020 11:11
-
-
Save coldmanck/7c459fa4039c84885d03f1a799ce6413 to your computer and use it in GitHub Desktop.
LeetCode 0063 combination sum (DP)
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]]: | |
cache = [[] for _ in range(target + 1)] | |
cache[0] = [[]] | |
for c in candidates: | |
for i in range(target + 1): | |
if i >= c: | |
for temp_ans in cache[i - c]: | |
cache[i].append(temp_ans + [c]) | |
return cache[-1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment