Oneline python solution with O(n) time

Brilliant solution OP. @jienhua Maybe this will help you. https://www.cs.umd.edu/class/sum2003/cmsc311/Notes/BitOp/xor.html

@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