class Solution { public List<List<Integer>> combine(int n, int k) { List<List<Integer>> res=new ArrayList<List<Integer>>(); combine(n, k, new ArrayList<Integer>(), res); return res; } private void combine(int num, int k, List<Integer> list, List<List<Integer>> res){ if(k==0) { res.add(new ArrayList<Integer>(list)); return; } if(num==0) return; combine(num-1,k,list,res); list.add(num); combine(num-1,k-1,list,res); list.remove(list.size()-1); } }