1、用双重循环逐个遍历(超时)

2、用list B的append和remove函数(超时)

3、用dict B(AC)

 class Solution:
# @param A, a list of integer
# @return an integer
def singleNumber(self, A):
B = {}
for i in A:
if i not in B:
B[i] = 1
else:
B[i] = 2
for i in B:
if B[i] == 1:
ret = i
break
return ret

leetcode:Single Number【Python版】的更多相关文章

  1. leetcode Single Number python

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

  2. [leetcode]Single Number II @ Python

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

  3. LeetCode Single Number I II Python

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

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

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

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

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

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

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

  7. LeetCode Single Number I / II / III

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

  8. LeetCode:Single Number II

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

  9. LeetCode Single Number III

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

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

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

随机推荐

  1. English trip WeekEnd-Lesson 2018.11.10

    本周末上了三节课,做个小结吧\(^o^)/~: [102] 新概念一早读 - 27 - 28        Teacher: March Mrs. Smith's living room is lar ...

  2. 『Kaggle』分类任务_决策树&集成模型&DataFrame向量化操作

    决策树这节中涉及到了很多pandas中的新的函数用法等,所以我单拿出来详细的理解一下这些pandas处理过程,进一步理解pandas背后的数据处理的手段原理. 决策树程序 数据载入 pd.read_c ...

  3. spring--boot @Valid的使用

    spring--boot @Valid的使用 每天一个小知识点,每天进步一点点,总结是积累. springBoot @Valid的使用,解释一下.就是给摸个bean类属性(数据库字段)加一个门槛,比如 ...

  4. iOS UI-团购案例(通过xib文件自定义UITableViewCell)

    一.Model #import <Foundation/Foundation.h> @interface Goods : NSObject @property (nonatomic, co ...

  5. gdb调试分析多线程死锁

    转载: http://blog.chinaunix.net/uid-30343738-id-5757210.html #include <stdio.h> #include <pth ...

  6. 文件的移动,删除 rename remove unlink 函数

    int rename(const char *oldpath, const char *newpath); rename()  renames  a  file,  moving it between ...

  7. Chrome nacl开启

    Chrome nacl开启

  8. linux command curl and sha256sum implement download verification package

    example: download_etcher_cli(){ local url="https://github.com/resin-io/etcher/releases/download ...

  9. HeadFirstJava

    java执行过程的来龙去脉 源代码——编译器——输出——java虚拟机 扩展名为.java ——扩展名为.class 不要直接用类名点变量来改变属性值,一般都用get.set方法.封装的基本原则:将你 ...

  10. Solr增删改查索引

    一.添加索引,提交文档 1.如图,我的xml文档有predicate.object字段,这些在Solr配置文档里没有,所以xml文档提交不了 2.在F:\solr-4.10.0\example\sol ...