import java.util.ArrayList;
import java.util.List;

public class Solution {
    public List<List<Integer>> combine(int n, int k) {
        if (k == n || k == 0) {
            List<Integer> tmp = new ArrayList<>();
            for (int i = 1; i <= k; i++) tmp.add(i);
            List<List<Integer>> result = new ArrayList<>();
            result.add(tmp);
            return result;
        }

        List<List<Integer>> result = combine(n - 1, k - 1);
        result.forEach(e -> e.add(n));
        result.addAll(combine(n - 1, k));
        return result;
    }
}

@@ -136,31 +136,60 @@
     
-if (k == n %7C%7C k == 0) %7B
+ArrayList%3CList%3CInteger%3E%3E result = new ArrayList%3C%3E();
 %0A   
@@ -189,28 +189,29 @@
 ();%0A        
-    
+Array
 List%3CInteger
@@ -249,52 +249,199 @@
     
-    for (int i = 1; i %3C= k; i++) tmp.add(i);
+helper(result, tmp, n, k);%0A        return result;%0A    %7D%0A%0A    private void helper(ArrayList%3CList%3CInteger%3E%3E result, ArrayList%3CInteger%3E arrayList, int n, int k) %7B%0A        if (k == 0 %7C%7C k == n) %7B
 %0A   
@@ -441,37 +441,37 @@
 ) %7B%0A            
-List%3C
+Array
 List%3CInteger%3E%3E r
@@ -463,32 +463,28 @@
 ist%3CInteger%3E
-%3E result
+ tmp
  = new Array
@@ -494,66 +494,161 @@
 t%3C%3E(
-);%0A            result.add(tmp);%0A            return result;
+arrayList);%0A            for (int i = 1; i %3C= k; i++) tmp.add(i);%0A            result.add(tmp);%0A        %7D else %7B%0A            for (int i = n; i %3E= k; i--) %7B
 %0A   
@@ -656,19 +656,16 @@
     
-%7D%0A%0A
         
 List
@@ -660,21 +660,21 @@
         
-List%3C
+Array
 List%3CInt
@@ -682,78 +682,68 @@
 ger%3E
-%3E result = combine(n - 1, k - 1);%0A        result.forEach(e -%3E e
+ tmp = new ArrayList%3C%3E(arrayList);%0A                tmp
 .add(
-n)
+i
 );%0A 
@@ -753,39 +753,48 @@
     
-result.addAll(combine(n
+        helper(result, tmp, i
  - 1, k
-)
+ - 1
 );%0A 
@@ -796,35 +796,36 @@
 1);%0A        
-return result;
+    %7D%0A        %7D
 %0A    %7D%0A%7D%0A

update #77