1 # -*- coding:utf-8 -*- 2 class Solution: 3 # 返回[a,b] 其中ab是出现一次的两个数字 4 def FindNumsAppearOnce(self, array): 5 diff = 0 6 for num in array: 7 diff ^= num 8 diff &= -diff 9 num1 = [0] 10 num2 = [0] 11 for num in array: 12 if num & diff == 0: 13 num1[0] ^= num 14 else: 15 num2[0] ^= num 16 return [num1[0],num2[0]] 17 # write code here
原文地址:https://www.cnblogs.com/asenyang/p/11024531.html
时间: 2024-09-30 07:28:41