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
Came upon this code through google search
codility/src/codility/OddOccurrencesInArray.java
Lines 41 to 46 in 6ddaf5e
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