List<List<Integer>> res=new ArrayList<>(); public List<List<Integer>> combine(int n, int k) { if (n==0||k==0)return res; dfs(n,k,new LinkedList<Integer>(),1); return res; }
privatevoiddfs(int n, int k, LinkedList<Integer> track,int index){ if (track.size() == k) { res.add(new ArrayList<>(track)); return; } for (int i = index; i <= n; i++) { track.add(i); dfs(n,k,track,i+1); track.removeLast(); } }