标签:self strong lis solution 一个 异或 size highlight ret
一、只出现一次的数字
题目描述:给定一个非空整数数组,除了某个元素只出现一次以外,其余每个元素均出现两次。找出那个只出现了一次的元素
示例 1:
输入: [2,2,1]
输出:1
示例 2:
输入:[4,1,2,1,2]
输出:4
考察:
异或运算及其交换律
class Solution:
def singleNumber(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
a = 0
for num in nums:
a = a ^ num
return a
标签:self strong lis solution 一个 异或 size highlight ret
原文地址:https://www.cnblogs.com/always-fight/p/10301239.html