Last active
March 15, 2019 03:07
-
-
Save ChongyeWang/9ae344a350a80c4f11ad834ae5fd7d51 to your computer and use it in GitHub Desktop.
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
class Solution(object): | |
class Solution(object): | |
def combinationSum(self, candidates, target): | |
""" | |
:type candidates: List[int] | |
:type target: int | |
:rtype: List[List[int]] | |
""" | |
res = [] | |
temp = [] | |
candidates = sorted(candidates) | |
self.backtracking(candidates, res, temp, target, 0) | |
return res | |
def backtracking(self, candidates, res, temp, remain, start): | |
if remain < 0 : return | |
if remain == 0: res.append(temp[:]) | |
for i in range(start, len(candidates)): | |
temp.append(candidates[i]) | |
self.backtracking(candidates, res, temp, remain - candidates[i], i) | |
temp.pop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment