Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution(object):
- def combinationSum2(self, candidates, target):
- results = []
- candidates.sort()
- def helper(nums, tar, i, slate):
- if sum(slate) == tar:
- temp = slate[:]
- results.append(temp)
- return
- if sum(slate) > tar:
- return
- if i == len(nums):
- return
- count = 0
- idx = i
- while idx < len(nums) and nums[idx] == nums[i]:
- count+=1
- idx+=1
- helper(nums, tar, idx, slate)
- for c in range(1, count+1):
- slate.append(nums[i])
- helper(nums, tar, idx, slate)
- for c in range(1, count+1):
- slate.pop()
- helper(candidates, target, 0, [])
- return(results)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement