@@ -0,0 +1,1222 @@
+/*%0A *Key point: dfs, like Subsets, Permutation, Combination Sum%0A */%0A%0Apublic class Solution %7B%0A    public ArrayList%3CArrayList%3CInteger%3E%3E combine(int n, int k) %7B%0A        //n should be greater than or equal to k%0A        if(n %3C k)%7B%0A            k = n;%0A        %7D%0A        %0A        ArrayList%3CArrayList%3CInteger%3E%3E result = new ArrayList%3CArrayList%3CInteger%3E%3E();%0A        ArrayList%3CInteger%3E temp = new ArrayList%3CInteger%3E();%0A        if(n %3C= 0)%0A            return result;%0A        %0A        //start point is 1 rather than 0 because it isn't an array, count is 0 when begin    %0A        dfsWorker(n, k, 1, 0, result, temp);    %0A            %0A        return result;%0A    %7D%0A    %0A    //start is the start point while count is how many elements we have%0A    public void dfsWorker(int n, int k, int start, int count, ArrayList%3CArrayList%3CInteger%3E%3E result, ArrayList%3CInteger%3E temp)%7B%0A        if(count == k)%7B%0A            result.add(new ArrayList%3CInteger%3E(temp));%0A            return;%0A        %7D%0A        %0A        for(int i = start;i%3Cn+1;i++)%7B%0A            temp.add(i);%0A            %0A            //take care of i+1, I made typo as start+1 several times%0A            dfsWorker(n,k,i+1,count+1,result,temp);%0A            temp.remove(temp.size()-1);%0A        %7D%0A    %7D%0A%7D

Solve Combinations