7/18/2020

[LeetCode] 136. Single Number

Problem : https://leetcode.com/problems/single-number/

Because A xor A xor B = B. The code xor all numbers together to find the unique number.


from operator import xor

class Solution:
    def singleNumber(self, nums: List[int]) -> int:
        return reduce(xor, nums)

No comments:

Post a Comment