I have completed this question and I am wondering what is the fastest way to solve it.
The question is "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
I came up with the solution:
from collections import Counter def find_uniq(arr): nums = list(Counter(arr).items()) data = [i for i in nums if i == 1] return data
I decided on using
Counter because I felt comfortable using it but when looking at others answers some use sets and others use counter as well.
I am wondering is my code sufficient and which method to solving this question would lead to the fastest time complexity?
[0, 1]? \$\endgroup\$