leetcode 136. 只出现一次的数字 Single Number

两个相同的数字异或等于1,任意数字异或0保持不变,因此所有数全部异或就能找到那个数。

 

python:

class Solution:
    def singleNumber(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        res = 0
        for i in nums:
            res = res^i
        return res

 

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务