https://leetcode-cn.com/problems/combinations/solution/hui-su-suan-fa-jian-zhi-python-dai-ma-java-dai-ma-/
class Solution { public List<List<Integer>> combine(int n, int k) { List<List<Integer>> res = new ArrayList<>(); backtrack(n, k, 1, new ArrayList<>(), res); return res; } private void backtrack(int n, int k, int start, List<Integer> path, List<List<Integer>> res){ if(path.size() == k){ res.add(new ArrayList<>(path)); return; } for(int i = start; i <= n - (k - path.size()) + 1; i++){ path.add(i); backtrack(n, k, i + 1, path, res); path.remove(path.size() - 1); } } }