注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
这样为什么能去重呢, 看到3sum, 4sum, subset, 和permutation 里面很多这样写来去重的?
我原来以为是因为 nums[i] 和 nums[i-1] 相同,
https://discuss.leetcode.com/top ... -easy-understand/16
cuyuan
Reputation: 3
For those who don't understand how to avoid duplicate by:
if "(i > cur && cand[i] == cand[i-1]) continue; when we should skip a number? not just it's the same as previous number, but also when it's previous number haven't been added! i > cur means cand[i - 1] is not added to the path (you should know why if you understand the algorithm), so if cand[i] == cand[i-1], then we shouldn't add cand[i]. This tricky is very smart.
看到这回复,感觉不是这样的,有点晕了,求解惑 谢谢
|