Advertisement
Guest User

Untitled

a guest
Nov 15th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. class Solution(object):
  2. def combinationSum(self, candidates, target):
  3. """
  4. :type candidates: List[int]
  5. :type target: int
  6. :rtype: List[List[int]]
  7. """
  8. result = []
  9. combinations = []
  10.  
  11. if(candidates == [] or len(candidates) == 0):
  12. return result
  13.  
  14. candidates.sort()
  15.  
  16. self.findTarget(result,combinations,candidates,target,0)
  17. return result
  18.  
  19. def findTarget(self, result, combinations, candidates, target, index):
  20. print(target, combinations)
  21. if(target == 0):
  22. result.append(combinations)
  23. return
  24.  
  25. for i in range(index,len(candidates)):
  26. if(candidates[i] > target):
  27. break
  28. combinations.append(candidates[i])
  29. self.findTarget(result, combinations, candidates, target - candidates[i], i)
  30. combinations.pop()
  31. return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement