Skip to content

Instantly share code, notes, and snippets.

@charlieanna
Created March 19, 2020 19:40
Show Gist options
  • Save charlieanna/bb06c736de63dc0ca3df7fa39ce98497 to your computer and use it in GitHub Desktop.
Save charlieanna/bb06c736de63dc0ca3df7fa39ce98497 to your computer and use it in GitHub Desktop.
class Solution:
def combinationSum2(self, nums: List[int], target: int) -> List[List[int]]:
nums.sort()
result = []
def helper(idx, temp, cur):
if cur == target :
result.append(temp[:])
if cur > target:
return
for i in range(idx, len(nums)):
if i > idx and nums[i] == nums[i-1]:
continue
temp.append(nums[i])
helper(i + 1, temp, cur + nums[i])
temp.pop()
helper(0, [], 0)
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment