How to find an odd number in an array? [closed]
In an array, there is exactly one element which repeats odd number of times and rest all other elements repeat even number of the times. Find the element optimally开发者_如何学运维
xor all the elements together.
Example:
In [3]: reduce( lambda x,y : x^y, [1, 2, 2, 1, 4, 5, 5] )
Out[3]: 4
精彩评论