Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def combinationSum3(self, k: int, n: int) -> List[List[int]]:
- combos = []
- currCombo = []
- def solve(num, rem, sz):
- if sz == k and rem == 0:
- combos.append(currCombo[:])
- return
- if num > 9 or rem < num or sz >= k:
- return
- solve(num+1, rem, sz)
- currCombo.append(num)
- solve(num+1, rem-num, sz+1)
- currCombo.pop()
- solve(1, n, 0)
- return combos
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement