class Solution(object):
def __init__(self):
self.res=[]
def _comb(self, candidates, target, pre):
for i in xrange(len(candidates)):
if target<candidates[i]:
break
if target==candidates[i]:
self.res.append(pre+[candidates[i]])
break
self._comb(candidates[i:], target-candidates[i], pre+[candidates[i]])
def combinationSum(self, candidates, target):
"""
:type candidates: List[int]
:type target: int
:rtype: List[List[int]]
"""
candidates.sort()
self._comb(candidates, target, [])
return self.res
递归套路