Given an array of integers, every element appears twice except for one. Find that single one.

Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?

#-------------------------------------------------------------------------------
# Name:        module1
# Purpose:
#
# Author:      ScottGu<gu.kai.66@gmail.com, 150316990@qq.com>
#
# Created:     13/11/2014
# Copyright:   (c) ScottGu<gu.kai.66> 2014
# Licence:     <your licence>
#-------------------------------------------------------------------------------

class Solution:
    # @param A, a list of integer
    # @return an integer
    def singleNumber(self, A):
        self.__init__()
        for num in A:
            if(self.dict.has_key(num)):
                self.dict[num]+=1
            else:
                self.dict[num]=1
        for p in self.dict.items():
            if(p[1]==1):
                return p[0]

    def __init__(self):
        self.dict={}

def main():

so=Solution()
arr=[1,1,2,2,3,3,4,4,5,6,6]
print arr
print so.singleNumber(arr)
arr=[1,2,2,3,3,4,4,5,6,6]
print arr
print so.singleNumber(arr)
arr=[1,1,2,3,3,4,4,5,6,6]
print arr
print so.singleNumber(arr)

arr=[1,1,2,2,3,3,4,4,5]
print arr
print so.singleNumber(arr)

arr=[1,0,1]
print arr
print so.singleNumber(arr)

arr=[1,0,0]
print arr
print so.singleNumber(arr)

LEETCODE —— Single Number的更多相关文章

  1. [LeetCode] Single Number III 单独的数字之三

    Given an array of numbers nums, in which exactly two elements appear only once and all the other ele ...

  2. [LeetCode] Single Number II 单独的数字之二

    Given an array of integers, every element appears three times except for one. Find that single one. ...

  3. [LeetCode] Single Number 单独的数字

    Given an array of integers, every element appears twice except for one. Find that single one. Note:Y ...

  4. LeetCode Single Number I / II / III

    [1]LeetCode 136 Single Number 题意:奇数个数,其中除了一个数只出现一次外,其他数都是成对出现,比如1,2,2,3,3...,求出该单个数. 解法:容易想到异或的性质,两个 ...

  5. LeetCode:Single Number II

    题目地址:here 题目大意:一个整数数组中,只有一个数出现一次,其余数都出现3次,在O(n)时间,O(1)空间内找到这个出现一次的数 对于”只有一个数出现一次,其余数出现2次“的情况,很简单,只要把 ...

  6. LeetCode Single Number III

    原题链接在这里:https://leetcode.com/problems/single-number-iii/ 题目: Given an array of numbers nums, in whic ...

  7. [leetcode]Single Number II @ Python

    原题地址:http://oj.leetcode.com/problems/single-number-ii/ 题意:Given an array of integers, every element ...

  8. LeetCode——Single Number II(找出数组中只出现一次的数2)

    问题: Given an array of integers, every element appears three times except for one. Find that single o ...

  9. LeetCode: Single Number I && II

    I title: Given an array of integers, every element appears twice except for one. Find that single on ...

  10. [LeetCode] Single Number III ( a New Questions Added today)

    Given an array of numbers nums, in which exactly two elements appear only once and all the other ele ...

随机推荐

  1. js执行顺序<转>

    JavaScript执行引擎并非一行一行地分析和执行程序,而是一段一段地分析执行的.而且在分析执行同一段代码中,定义式的函数语句会被提取出来优先执行.函数定义执行完后,才会按顺序执行其他代码. 先看看 ...

  2. JVM学习——编译OpenJDK

    最近在学习<深入理解java虚拟机 第二版>这本书.书中第一部分建议大家自己编译OpenJDK.抱着学习态度也来编译个玩一玩.下面进入正题. 1.编译环境介绍 操作系统 CentOS Li ...

  3. Nbimer族助手 部分控件不能用的解决方法(转)

    用户提出的问题现象: 我两天笔记本安装的都是win7 SP1系统,一台为64为一台为32位,网络环境是移动宽带通过D-Link路由器实现无线局域网,DHPC自动分配IP地址.每次打开IE或者Chrom ...

  4. lhgdialog: iframe页面里面的,确定,关闭、取消按钮的操作

    lhgdialog: iframe页面里面的,确定,关闭.取消按钮的操作 如果你正在用lhgdialog,用他人iframe,或者 content:'url:http://www.baidu.com/ ...

  5. Error: listen EADDRINUSE

    有可能是已经作用了18001端口 netstat -antp|grep 18001 kill 然后重启程序. events.js:72 throw er; // Unhandled 'error' e ...

  6. 在centos6.5中安装zookeeper集群

    简介 ZooKeeper服务器是用Java编写创建,它运行在JVM.所以需要使用JDK 6或更高版本,在这里就不说在centos安装jdk环境了,直接进入正题,我搭建的是 192.168.0.2, 1 ...

  7. 亚马逊云服务器AWS安装CentOS

    亚马逊云服务器默认创建的实例,在停止之后再启动的情况下,IP会发生改变.所以我们最好先创建一个弹性IP,即EIP,不过我也不清楚这个费用. 1.按如图操作创建一个弹性IP,弹性IP创建之后可以随便绑定 ...

  8. 20135203齐岳信息安全系统设计基础——实验四&实验五实验报告

    见20135217孙小博的博客:http://www.cnblogs.com/sunxiaobo/p/4991861.html

  9. Redis 集群解决方案 Codis

    (来源:开源中国社区 http://www.oschina.net/p/codis) Codis 是一个分布式 Redis 解决方案, 对于上层的应用来说, 连接到 Codis Proxy 和连接原生 ...

  10. oracle 11g 一直提示 严重: 监听程序未启动或数据库服务未注册到该监听程序

    From:http://blog.sina.com.cn/s/blog_6734ea6d0102v6sn.html 增加操作系统环境变量:ORACLE_HOSTNAME=localhost 然后在cm ...