classSolution{ public List<List<Integer>> combine(int n, int k) { List<List<Integer>> result = new ArrayList<List<Integer>>(); List<Integer> current = new ArrayList<Integer>(); bfs(result, current, n , k, 1); return result; } publicvoidbfs(List<List<Integer>> result, List<Integer> current, int n, int k, int c){ if(current.size() == k){ result.add(new ArrayList<Integer>(current)); return ; } for(int i=c; i<=n; i++){ current.add(i); bfs(result, current, n ,k, ++c); current.remove(current.size()-1); } } }