-
Notifications
You must be signed in to change notification settings - Fork 20k
add two sum problem #4364
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
add two sum problem #4364
Conversation
9011ca4
to
4fb3e7d
Compare
@siriak please check. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would highly recommend to add the missing test. Besides that, some small suggestions from my side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for a mammoth suggestion. Short summary:
- I suggest to use
Optional<Pair<Integer, Integer>>
as a return type. Why? If the solution exists, the output should be two numbers. I suggest it to encode this information into the return type (int[]
might be arbitrarily long), - I renamed
map
tovalueToIndex
. Maybe it is still not perfect, but stores some information what is the key and what is the value of this map, - renamed nums to values,
- adapted tests,
- added a new test, so that there is 100 % coverage.
@siriak check! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks!
Uh oh!
There was an error while loading. Please reload this page.