Skip to content

Instantly share code, notes, and snippets.

@domarps
Created August 12, 2018 20:27
Show Gist options
  • Save domarps/84bce8c8086371d581817028d0f66203 to your computer and use it in GitHub Desktop.
Save domarps/84bce8c8086371d581817028d0f66203 to your computer and use it in GitHub Desktop.
class Solution:
def helper(self, candidates, target, curr_comb, result, curr_id, curr_sum):
if curr_sum >= target:
if curr_sum == target:
result.append(curr_comb)
return
for i in range(curr_id, len(candidates)):
curr_comb.append(candidates[i])
self.helper(candidates, target, curr_comb, result, i, curr_sum + candidates[i])
curr_comb.pop()
def combinationSum(self, candidates, target):
"""
:type candidates: List[int]
:type target: int
:rtype: List[List[int]]
"""
result = []
self.helper(candidates, target, [], result, 0, 0)
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment