class Solution {
private void fill(int n, int k, int start, ArrayList<Integer> path, List<List<Integer>> ans) {
if (path.size() == k) {
ans.add(new ArrayList<>(path));
return;
}
for (int i = start; i < n; i++) {
path.add(i);
fill(n, k, i + 1, path, ans);
path.remove(path.size() - 1);
}
}
public List<List<Integer>> combine(int n, int k) {
List<List<Integer>> ans = new ArrayList<>();
ArrayList<Integer> path = new ArrayList<>(k);
fill(n + 1, k, 1, path, ans);
return ans;
}
}
11-23
1107
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
06-10
835
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
03-18
1057
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
09-14
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交