In this question at Code Review they tried to find the fastest way to return the unique element in an array where all the elements are the same except one. But what is the shortest code that accomplish the same thing?
Goal
Find the unique element in an array and return it.
Rules
- The input array will contain only integer, strictly positive numbers, so you can use 0 as the end of the input if your language needs it.
- The size of the array will be at least 3 and will have a finite size. You can limit the size of the array to any limit your language has.
- Every element in the array will be the same, except for one which will be different.
- You must output the value (not the position) of the unique element in any standard format. You can output leading or trailing spaces or newlines.
- You can take the input array in any accepted format.
Examples
Input Output
------------------------------
[ 1, 1, 1, 2, 1, 1 ] 2
[ 3, 5, 5, 5, 5 ] 3
[ 9, 2, 9, 9, 9, 9, 9 ] 2
[ 4, 4, 4, 6 ] 6
[ 5, 8, 8 ] 5
[ 8, 5, 8 ] 5
[ 8, 8, 5 ] 5
Winner
This is code-golf, so may the shortest code for each language win!
[8, 8, 5]
and[5, 8, 8]
since there isn't one were the last element is unique and 3 element arrays are a corner cases in themselves. \$\endgroup\$