# One-line python solution with O(n) time

• ``return reduce(lambda x, y: x ^ y, nums)``

• Hello, I really want to be able to understand your solution. I understand the reduce(lambda...), however I do not understand the x ^ y (bitwise XOR) part. Can anyone explain this part to me please Q__Q?

• XOR operate gets 0 with two same numbers so the final result of a sequence XOR operates in the array is the number which only appears once(Other duplicated numbers generate 0).

• @jienhua XOR means you can exchange the order and y XOR y equals 0,for example:
x^y^z=z^x^y=x^z^y,so if you want calculate the {2,1,5,1,2},you use XOR like this:
ans=2^1^5^1^2=1^1^2^2^5=(1^1)^(2^2)^5=0^0^5=5
so show my code:

``````class Solution(object):
def singleNumber(self, nums):
ret=0
for i in range(len(nums)):
ret^=nums[i]
return ret

``````

• Why have I never used reduce or ^ in almost three years of writing python!? Great solution.

• greet solution

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.