关键是找到a和b第k位上一个为0一个为1,然后再与第k位上为1的异或 class Solution: def singleNumber(self, nums): """ :type nums: List[int] :rtype: List[int] """ a1=a2=0 for n in nums: a1^=n k = a1&(~a1+1) for n in nums: if n&k: a2^=n return [a2,a1^a2]