Given an array of integers, every element appears # twice except for one. Find that single one.

class Solution(object):
    def singleNumber(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        xor = 0
        for num in nums:
            xor ^= num
        return xor
x=Solution()
print(x.singleNumber([2,5,2,6,7,6,7]))

 输出:

5

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-04
  • 2022-12-23
  • 2021-11-05
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-07
  • 2021-08-29
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案