Skip to content

odd number selection bug #2

@rayary

Description

@rayary

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions