力扣labuladong一刷day7共3题
一、216. 组合总和 III
题目链接:https://leetcode.cn/problems/combination-sum-iii/
思路:还是组合只是既有n又有k。
class Solution {
List<List<Integer>> arrayLists = new ArrayList<>();
List<Integer> list = new ArrayList<>();
int sum = 0;
public List<List<Integer>> combinationSum3(int k, int n) {
backTracking(k, n, 1);
return arrayLists;
}
void backTracking(int k, int n, int index) {
if (list.size() == k && sum == n) {
arrayLists.add(new ArrayList<>(list));
return;
}
if (list.size() > k) return;
for (int i = index; i <= 9

本文介绍了在力扣LeetCode平台上的一天7题,包括组合总和III的回溯算法、二叉树的最小深度使用层序遍历,以及打开转盘锁问题的广度优先搜索解法。
最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



