반응형
You are given an odd-length array of integers, in which all of them are the same, except for one single number.
Complete the method which accepts such an array, and returns that single different number.
The input array will always be valid! (odd-length >= 3)
Examples
[1, 1, 2] ==> 2
[17, 17, 3, 17, 17, 17, 17] ==> 3
Solution:
def stray(arr):
import collections
return [k for k, v in collections.Counter(arr).items() if v == 1].pop()
Other Solution:
def stray(arr):
return min(arr, key=arr.count)
반응형
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
Sum of Minimums! (0) | 2022.08.21 |
---|---|
Flatten and sort an array (0) | 2022.08.20 |
5 without numbers !! (0) | 2022.08.19 |
If you can't sleep, just count sheep!! (0) | 2022.08.17 |
Row Weights (0) | 2022.08.16 |