leetcode Single Number II python

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

posted @ 2015-06-14 06:35  轻抚离殇  阅读(275)  评论(0编辑  收藏  举报