Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution(object):
- def combinationSum(self, candidates, target):
- """
- :type candidates: List[int]
- :type target: int
- :rtype: List[List[int]]
- """
- result = []
- combinations = []
- if(candidates == [] or len(candidates) == 0):
- return result
- candidates.sort()
- self.findTarget(result,combinations,candidates,target,0)
- return result
- def findTarget(self, result, combinations, candidates, target, index):
- print(target, combinations)
- if(target == 0):
- result.append(combinations)
- return
- for i in range(index,len(candidates)):
- if(candidates[i] > target):
- break
- combinations.append(candidates[i])
- self.findTarget(result, combinations, candidates, target - candidates[i], i)
- combinations.pop()
- return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement