开发者

How to find an odd number in an array? [closed]

开发者 https://www.devze.com 2023-03-15 23:57 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消