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. Android NDK开发入门实例

    AndroidNDK是能使Android应用开发者把从c/c++编译而来的本地代码嵌入到应用包中的一系列工具的组合. 注意: AndroidNDK只能用于Android1.5及以上版本中. I. An ...

  2. Hibernate <查询缓存>

    查询缓存: 定义:查询缓存它是基于二级缓存的,可以保存普通属性查询的结果,查询对象实体时,他会保存id作为键,查询结果作为值,下个对象访问时,可以直接查到 查询缓存查询实体对象时,显著的特点是,会执行 ...

  3. fifter过滤器

    package fifter; import java.io.IOException;import javax.servlet.Filter;import javax.servlet.FilterCh ...

  4. div 一段时间后自动隐藏

    一.div弹出后自动消失 这里并没有删除 setTimeout(function(){$(".alert").hide();},2000); 直接在js文件中需要的地方添加执行这段 ...

  5. Mac下安装Wireshark,双击闪退

     Mac OS X上使用Wireshark抓包(http://blog.csdn.net/phunxm/article/details/38590561) Mac下安装Wireshark /Appli ...

  6. AngularJS事件绑定的使用详解

    本文和大家分享的主要是AngularJS中事件绑定相关知识点,希望通过本文的分享,对大家学习和使用AngularJS有所帮助. 1.绑定事件:表达式.事件方法名: 2.绑定点击事件实例:显示.隐藏页面 ...

  7. C++ 高质量编程附录试题

    附录B :C++/C试题 本试题仅用于考查C++/C程序员的基本编程技能.内容限于C++/C常用语法,不涉及数据结构.算法以及深奥的语法.考试成绩能反映出考生的编程质量以及对C++/C的理解程度,但不 ...

  8. 读javascript高级程序设计13-JSON

    JSON是一个轻量级的数据格式,可以简化表示数据结构的工作量.在实际工作中,我们经常用它来传递数据,不过对于其使用的一些细节还是需要注意的.在ECMAScript5中定义了原生的JSON对象,可以用来 ...

  9. SSM框架学习之高并发秒杀业务--笔记2-- DAO层

    上节中利用Maven创建了项目,并导入了所有的依赖,这节来进行DAO层的设计与开发 第一步,创建数据库和表. 首先分析业务,这个SSM匡济整合案例是做一个商品的秒杀系统,要存储的有:1.待秒杀的商品的 ...

  10. 三星在GPL下发布其exFAT文件系统实现源码

    exFAT文件系统是微软的一个产品,设计让外置储存设备和PC之间实现无缝的TB级数据转移和数据交换,它只支持Windows和OS X,不支持Linux.作为一个含有大量专利的私有产品,没有人会预计它会 ...