Skip to content

Commit 837ff50

Browse files
authored
Merge pull request #10 from iamAntimPal/Leetcode-75
Leetcode 75
2 parents e003f54 + f04c4eb commit 837ff50

File tree

2 files changed

+779
-0
lines changed

2 files changed

+779
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution:
2+
def combinationSum3(self, k: int, n: int) -> List[List[int]]:
3+
def dfs(i: int, s: int):
4+
if s == 0:
5+
if len(t) == k:
6+
ans.append(t[:])
7+
return
8+
if i > 9 or i > s or len(t) >= k:
9+
return
10+
t.append(i)
11+
dfs(i + 1, s - i)
12+
t.pop()
13+
dfs(i + 1, s)
14+
15+
ans = []
16+
t = []
17+
dfs(1, n)
18+
return ans

0 commit comments

Comments
 (0)