Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. class Solution(object):
  2. class Solution(object):
  3. def combinationSum(self, candidates, target):
  4. """
  5. :type candidates: List[int]
  6. :type target: int
  7. :rtype: List[List[int]]
  8. """
  9. res = []
  10. temp = []
  11. candidates = sorted(candidates)
  12. self.backtracking(candidates, res, temp, target, 0)
  13. return res
  14. def backtracking(self, candidates, res, temp, remain, start):
  15. if remain < 0 : return
  16. if remain == 0: res.append(temp[:])
  17. for i in range(start, len(candidates)):
  18. temp.append(candidates[i])
  19. self.backtracking(candidates, res, temp, remain - candidates[i], i)
  20. temp.pop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement