Given a non-empty array of integers, every element appears twice except for
one. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement
it without using extra memory?
Example 1:
Input: [2,2,1]
Output: 1
Example 2:
Input: [4,1,2,1,2]
Output: 4
这网站似乎会规定几秒内跑完,所以在讨论区可以看到各种大师的解法
最让我不解的是,有人一行可以跑完这题..
解法是这样
class Solution(object):
def singleNumber(self, nums):
return reduce(lambda x, y: x^y,nums)
真的不懂啊啊啊
即使看过每一个函数关键字的作法(reduce,lambda,^)
都还是不懂...
有高手可以解释吗