Created
August 12, 2018 20:27
-
-
Save domarps/84bce8c8086371d581817028d0f66203 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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