Skip to content

fix: problems/220.contains-duplicate-iii.md #525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 10, 2022

Conversation

ToSnow
Copy link
Contributor

@ToSnow ToSnow commented Feb 9, 2022

虽然C++的代码能通过leetcode的所有测试用例,但其仍存在bug:
当擦除hashmap中的元素时,键的计算方法应该和插入时的计算方法一致。否则会错误地擦除需要的元素或者保留不需要的元素。
例如:
输入:nums = [-1,10,20,1], k = 2, t = 3
预期结果:false
实际输出:true
解释:当i = 3时, 删除了nums[i-k]/mod = 0的键,但实际上值"-1"存储在键为-1的桶中,造成i=4时的错误判断。

@azl397985856
Copy link
Owner

yes cpp 代码确实有这个问题,本质正如你所说,两次计算 key 的方式不同

@azl397985856 azl397985856 merged commit 01b82a9 into azl397985856:master Feb 10, 2022
azl397985856 added a commit that referenced this pull request Aug 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants