Skip to content
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

Update 0001.两数之和.md #2882

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

Conversation

buptz2b
Copy link

@buptz2b buptz2b commented Feb 4, 2025

命名更直观:val 和 preIndex 改为了 num 和 complement,让代码更易于理解。
返回值:使用 nil 代替空切片,符合 Go 语言的惯例。当找不到符合条件的答案时返回 nil,而不是一个空切片。这样可以在后续代码中区分是否有解(nil 表示没有解)。
提前计算补数:通过将 complement := target - num 提前计算出来,使得代码结构更清晰,容易理解。

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