Skip to content

Update 3. 数组中重复的数字.md #1418

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gyl1041
Copy link

@gyl1041 gyl1041 commented Jun 10, 2025

这里第二次调用是多余的!
duplicate 中每一次for循环的目的都是为了让 nums[i] == i ,也就是第 i 个位置等于 i 。 所以 while 循环要么找到重复数字return,要么结束循环后使得 nums[i] == i ,这时候再调用 swap(nums, i, nums[i]) 没有任何意义

这里第二次调用是多余的!
duplicate 中每一次for循环的目的都是为了让 nums[i] == i ,也就是第 i 个位置等于 i 。
所以 while 循环要么找到重复数字return,要么结束循环后使得 nums[i] == i ,这时候再调用 swap(nums, i, nums[i]) 没有任何意义
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.

1 participant