알고리즘 문제/CodeWar
Find the unique number
BEstyle
2022. 9. 23. 13:02
DESCRIPTION:
There is an array with some numbers. All numbers are equal except for one. Try to find it!
find_uniq([ 1, 1, 1, 2, 1, 1 ]) == 2
find_uniq([ 0, 0, 0.55, 0, 0 ]) == 0.55
It’s guaranteed that array contains at least 3 numbers.
The tests contain some very huge arrays, so think about performance.
def find_uniq(arr):
arr.sort()
if arr[0]==arr[1]:
return arr[-1]
else:
return arr[0]