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,^)
都還是不懂...
有高手可以解釋嗎