S2 icon indicating copy to clipboard operation
S2 copied to clipboard

0040. Combination Sum I I | LeetCode Cookbook

Open halfrost opened this issue 4 years ago • 2 comments

https://books.halfrost.com/leetcode/ChapterFour/0001~0099/0040.Combination-Sum-II/

halfrost avatar Feb 15 '21 03:02 halfrost

请问为什么”if i > index && nums[i] == nums[i-1]“可以去除结果中的重复组合?

smart2003 avatar Nov 04 '21 07:11 smart2003

@smart2003 当 i 比 index 大的时候,并且 nums[i] == nums[i-1] 的时候,这个时候 i 产生的解是重复解,所以直接 continue,避免代码执行到下面,把重复解加入到最终的答案数组中。

halfrost avatar Nov 07 '21 03:11 halfrost