Skip to content

Instantly share code, notes, and snippets.

@ChongyeWang
Last active March 15, 2019 03:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChongyeWang/9ae344a350a80c4f11ad834ae5fd7d51 to your computer and use it in GitHub Desktop.
Save ChongyeWang/9ae344a350a80c4f11ad834ae5fd7d51 to your computer and use it in GitHub Desktop.
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