Single Number II
Given an array of integers, every element appears three times except for one. Find that single one.
python code:
class Solution:
# @param {integer[]} nums
# @return {integer}
def singleNumber(self, nums):
B={}
for eachint in nums:
if eachint not in B: #建立一个dict,遍历list,统计每个key出现的次数
B[eachint]=1
else:
B[eachint]+=1
for eachint in B:
if B[eachint] is not 3: #找出出现次数不为3的key,return
break
return eachint