本文共 286 字,大约阅读时间需要 1 分钟。
0异或任何数字都是数字本身,相同的数字异或为0,同时异或有交换律,不因数字的顺序改变,所有相同的经过异或均变为0,和唯一的一个数字异或后就为那个数字。
class Solution(object): def singleNumber(self, nums): """ :type nums: List[int] :rtype: int """ rtype=0 for i in nums: rtype = rtype^i return rtype
转载地址:http://pjnmd.baihongyu.com/