We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a60822a commit bbb72e6Copy full SHA for bbb72e6
1 file changed
src/com/leetcode/Main77.java
@@ -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