码迷,mamicode.com
首页 > 编程语言 > 详细

leetcode Single Number II python

时间:2015-06-14 06:57:52      阅读:330      评论:0      收藏:0      [点我收藏+]

标签:

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

leetcode Single Number II python

标签:

原文地址:http://www.cnblogs.com/bthl/p/4574522.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!