标签:index app subject div bsp question elf lse describe
1 # -*- coding:utf-8 -*-
2 class Solution:
3 def FindNumsAppearOnce(self, array):
4 # write code here
5 if not array or len(array) < 2:
6 return 0
7 temp = 0
8 res1 = 0
9 res2 = 0
10 for i in array:
11 temp = temp ^ i
12 # temp中1在的索引
13 indexof1 = self.findIndex1(temp)
14 for j in array:
15 if self.is1(j,indexof1):
16 res1=res1^j
17 else:
18 res2 = res2^j
19 return res1,res2
20
21 def findIndex1(self,num):
22 23 n = 0
24 while num &1==0:
25 num = num>>1
26 n +=1
27 return n
28 def is1(self,num,index1):
29 if (num>>index1)&1:
30 return True
31 else:
32 return False
标签:index app subject div bsp question elf lse describe
原文地址:https://www.cnblogs.com/shuangcao/p/12773612.html