77.组合
public List<List<Integer>> combine(int n, int k) { if (n < k) { return null; } List<List<Integer>> list = new ArrayList<>(); List<Integer> path = new ArrayList<>(); backSource(n, path, list, k); return list; } public void backSource(int n, List<Integer> path, List<List<Integer>> list, int k) { if (path.size() > k) { return; } if (path.size() == k) { list.add(new ArrayList<>(path)); return; } for (int i = 1; i <= n; i++) { if (!path.contains(i)) { path.add(i); backSource(i, path, list, k); path.remove(path.size() - 1); } } }