def singleNumber(self, nums):
return reduce(lambda a,b:a^b, nums)
Is it executed in linear time?
Yes, it is. Reduce means apply function of two arguments cumulatively to the items of iterable(a list etc), from left to right, so as to reduce the iterable to a single value.
Can also be: return reduce(operator.xor, nums)
return reduce(operator.xor, nums)
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.