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

odd number selection bug #2

Open
rayary opened this issue Feb 28, 2018 · 0 comments
Open

odd number selection bug #2

rayary opened this issue Feb 28, 2018 · 0 comments

Comments

@rayary
Copy link

rayary commented Feb 28, 2018

Came upon this code through google search

for (int i = 0; i < A.length; i++) {
if (dups.add(A[i])) {
elem = A[i];
}
}
return elem;

If the input array is arranged so that the odd number occurs before the pairs, the output will be the last number did not exist in the set, which may not necessarily be the odd number.
for example, {7, 9, 3, 9, 3, 9, 9} will return 3

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

No branches or pull requests

1 participant