题解 | #数组中只出现一次的数(其它数出现k次)#
数组中只出现一次的数(其它数出现k次)
http://www.nowcoder.com/practice/5d3d74c3bf7f4e368e03096bb8857871
class Solution:
def int_overflow(self,val):
maxint = 2147483647
if not -maxint-1 <= val <= maxint:
val = (val + (maxint + 1)) % (2 * (maxint + 1)) - maxint - 1
return val
def foundOnceNumber(self , arr , k ):
# write code here
res = 0
for i in range(32):
tmp = 0
for num in arr:
# if num<0:num = ((~num)+1)&0xffffffff
tmp += num >> i & 1
if tmp%k != 0:
res += 1<<i
return res-2**32 if res>>31&1 else res 
查看21道真题和解析
SHEIN希音公司福利 248人发布