package com.fishercoder.solutions;


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

/**Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.

 For example,
 If n = 4 and k = 2, a solution is:

 [
 [2,4],
 [3,4],
 [2,3],
 [1,2],
 [1,3],
 [1,4],
 ]*/
public class _77 {
    public List<List<Integer>> combine(int n, int k) {
        List<List<Integer>> result = new ArrayList();
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = i + 1;
        }
        backtracking(k, 0, nums, new ArrayList(), result);
        return result;
    }

    void backtracking(int k, int start, int[] nums, List<Integer> temp, List<List<Integer>> result) {
        if (temp.size() == k) {
            List<Integer> newTemp = new ArrayList(temp);
            result.add(newTemp);
        } else if (temp.size() < k) {
            for (int i = start; i < nums.length; i++) {
                temp.add(nums[i]);
                backtracking(k, i + 1, nums, temp, result);
                temp.remove(temp.size() - 1);
            }
        }
    }

}

@@ -85,16 +85,43 @@
 st;%0A%0A/**
+%0A * 77. Combinations%0A *%0A * 
 Given tw
@@ -311,11 +311,14 @@
 ,%0A %5D
+%0A 
 */%0A
+%0A
 publ
@@ -332,16 +332,17 @@
 s _77 %7B%0A
+%0A
     publ
@@ -707,20 +707,20 @@
 nteger%3E 
-temp
+curr
 , List%3CL
@@ -751,28 +751,28 @@
         if (
-temp
+curr
 .size() == k
@@ -791,83 +791,38 @@
     
-List%3CInteger%3E newTemp = new ArrayList(temp);%0A            result.add(newTemp
+result.add(new ArrayList(curr)
 );%0A 
@@ -839,20 +839,20 @@
 lse if (
-temp
+curr
 .size() 
@@ -930,20 +930,20 @@
         
-temp
+curr
 .add(num
@@ -994,20 +994,20 @@
 , nums, 
-temp
+curr
 , result
@@ -1029,20 +1029,20 @@
     
-temp
+curr
 .remove(
 temp
@@ -1041,12 +1041,12 @@
 ove(
-temp
+curr
 .siz

refactor 77