leetcode 题目链接 1. 题目考点 n叉树 dfs回溯+剪枝 2. 考点解析 回溯 + 两次剪枝 class Solution { List<List<Integer>> res = new ArrayList<>(); public List<List<Integer>> combine(int n, int k) { Stack<Integer> combine = new Stack<>(); dfs(n, k, 1, combine); return res; } public void dfs(int n, int k, int begin, Stack<Integer> combine) { if (combine.size() == k) { res.add(new ArrayList(combine)); return ; } for (int i = begin; i <= n; i++) { if (combine.contains(i)) continue; combine.push(i); dfs(n, k, i+1, combine); combine.pop(); } } }