leetcode 查找每个元素都出现两次的列表,返回只出现一次的元素

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
原文地址:https://www.cnblogs.com/sea-stream/p/10567249.html