How to Find the odd int in Java
The challenge
Given an array of integers, find the one that appears an odd number of times.
There will always be only one integer that appears an odd number of times.
The solution in Java code
Option 1 (using streams
):
Option 2 (using xor
):
Option 3 (using a TreeSet
):
Test cases to validate our solution
|
|