Update notes for s0040

This commit is contained in:
2023-02-03 12:14:39 +08:00
parent ca4fe2293d
commit fe6a4ec73f
2 changed files with 32 additions and 2 deletions

View File

@@ -14,7 +14,7 @@ void combinationSum2DFS(vector<int> &candidates, int target, int startIndex,
for (int i = startIndex; i < size; ++i) {
// 剪枝,当现在节点的 sum 已经超过了 target就没必要继续迭代了
if (sum + candidates[i] > target) break;
// 剪枝,要对同一树层使用过的元素进行跳过
// 剪枝,但保留树枝重复的情况
if (i > 0 && candidates[i] == candidates[i - 1] && used[i - 1] == false)
continue;
path.push_back(candidates[i]);