这是四则或许对你有帮助的讯息
1、👉 最近我发现了一个每日都会推送最新校招资讯的《校招日程》文档,其中包括往届补录、应届实习校招信息,比如各种大厂、国企、银行、事业编等信息都会定期更新,帮忙扩散一下。
2、😍 免费分享阿秀个人学习计算机以来的收集到的免费资源,点此白嫖。
3、🚀如果你想在校招中顺利拿到更好的offer,阿秀建议你多看看前人踩过的坑和留下的经验,事实上你现在遇到的大多数问题你的学长学姐师兄师姐基本都已经遇到过了。
4、🔥 欢迎准备计算机校招的小伙伴加入我的学习圈子,一个人踽踽独行真的不如一群人报团取暖,过去22届和23届的小伙伴好好跟着走下去的,最后基本都拿到了不错的offer!如果你需要《阿秀的学习笔记》网站中📚︎校招八股文相关知识点的PDF版本的话,可以点此下载 。
# 40. 组合总和 II
力扣原题链接(点我直达) (opens new window)
给定一个数组 candidates
和一个目标数 target
,找出 candidates
中所有可以使数字和为 target
的组合。
candidates
中的每个数字在每个组合中只能使用一次。
说明:
- 所有数字(包括目标数)都是正整数。
- 解集不能包含重复的组合。
示例 1:
输入: candidates = [10,1,2,7,6,1,5], target = 8,
所求解集为:
[
[1, 7],
[1, 2, 5],
[2, 6],
[1, 1, 6]
]
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
示例 2:
输入: candidates = [2,5,2,1,2], target = 5,
所求解集为:
[
[1,2,2],
[5]
]
1
2
3
4
5
6
2
3
4
5
6
# 1、关键在于去重
执行用时:0 ms, 在所有 C++ 提交中击败了100.00%的用户
内存消耗:7.1 MB, 在所有 C++ 提交中击败了100.00%的用户
void combinationSum2Core(vector<int>& candidates, vector<vector<int>>& result, vector<int>& temp, int target, int begin, int sum) {
if (sum == target)
{
result.push_back(temp);
return;
}
for (int i = begin; i < candidates.size(); ++i)
{
if (i > begin && candidates[i] == candidates[i - 1]) continue;
if (sum + candidates[i] <= target) {
temp.push_back(candidates[i]);
combinationSum2Core(candidates, result, temp, target, i + 1, sum + candidates[i]);
temp.pop_back();
}
else
return;
}
}
vector<vector<int>> combinationSum2(vector<int>& candidates, int target) {
sort(candidates.begin(), candidates.end());
vector<int>temp;
vector<vector<int>> result;
combinationSum2Core(candidates, result, temp, target, 0, 0);
return result;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30