Skip to content

Commit c83c34e

Browse files
iamAntimPalAntim-IWPIamShiwangi
committed
Create 216. Combination Sum III.py
Co-Authored-By: Antim-IWP <203163676+Antim-IWP@users.noreply.github.com> Co-Authored-By: Shiwangi Srivastava <174641070+IamShiwangi@users.noreply.github.com>
1 parent 02e9a62 commit c83c34e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-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)