Skip to content

Commit bbb72e6

Browse files
committed
ok
1 parent a60822a commit bbb72e6

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

src/com/leetcode/Main77.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.leetcode;
2+
3+
import java.util.LinkedList;
4+
import java.util.List;
5+
6+
public class Main77 {
7+
public List<List<Integer>> res = new LinkedList<>();
8+
public void cur(LinkedList<Integer> curr, int n ,int k, int first) {
9+
if (curr.size() == k) {
10+
res.add(new LinkedList<>(curr));
11+
return;
12+
}
13+
for (int i = first; i <= n; i++) {
14+
curr.add(i);
15+
cur(curr, n, k, i + 1);
16+
curr.removeLast();
17+
}
18+
}
19+
public List<List<Integer>> combine(int n, int k) {
20+
LinkedList<Integer> cur = new LinkedList<>();
21+
cur(cur, n, k, 1);
22+
return res;
23+
}
24+
25+
public static void main(String[] args) {
26+
int n = 4;
27+
int k = 2;
28+
Main77 m = new Main77();
29+
System.out.println(m.combine(n, k));
30+
}
31+
}

0 commit comments

Comments
 (0)