MCPcopy Create free account
hub / github.com/Hsinha11/Leetcode-solutions / combinationSum

Method combinationSum

39-combination-sum/combination-sum.py:6–22  ·  view source on GitHub ↗
(self, candidates: List[int], target: int)

Source from the content-addressed store, hash-verified

4
5class Solution:
6 def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:
7 result = []
8
9 def backtrack(temp: List[int], remain: int, start: int):
10 if remain < 0:
11 return
12 if remain == 0:
13 result.append(temp[:])
14 return
15
16 for i in range(start, len(candidates)):
17 temp.append(candidates[i])
18 backtrack(temp, remain - candidates[i], i)
19 temp.pop()
20
21 backtrack([], target, 0)
22 return result

Callers

nothing calls this directly

Calls 1

backtrackFunction · 0.70

Tested by

no test coverage detected