public List<List<Integer>> combine(int n, int k) {
List<List<Integer>> result = new ArrayList<>();
if (n < k ){
return result;
}
List<Integer> path = new ArrayList<Integer>();
backtrack(result,path,k,1,n);
return result;
}
public void backtrack(List<List<Integer>> result,
List<Integer> path,
int k,
int start,
int n) {
if (path.size() == k){
result.add(new ArrayList<Integer>(path));
return;
}
for (int i = start; i <= n; i++) {
path.add(i);
backtrack(result, path, k, i+1, n);
path.remove(path.size()-1);
}
}