-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0077-Combinations.cs
More file actions
37 lines (30 loc) · 844 Bytes
/
0077-Combinations.cs
File metadata and controls
37 lines (30 loc) · 844 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System;
using System.Collections.Generic;
using System.Text;
namespace Solution._0077.Combinations
{
public class _0077_Combinations
{
private IList<IList<int>> res = new List<IList<int>>();
public IList<IList<int>> Combine(int n, int k)
{
var temp = new List<int>();
recursive(n, k, temp, 1);
return res;
}
private void recursive(int n, int k, IList<int> temp, int level)
{
if (temp.Count == k)
res.Add(new List<int>(temp));
else
{
for (int i = level; i <= n; i++)
{
temp.Add(i);
recursive(n, k, temp, i + 1);
temp.RemoveAt(temp.Count - 1);
}
}
}
}
}