leetcode:Single Number【Python版】
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版】的更多相关文章
- leetcode Single Number python
#question : Given an array of integers, every element appears twice except for one. Find that single ...
- [leetcode]Single Number II @ Python
原题地址:http://oj.leetcode.com/problems/single-number-ii/ 题意:Given an array of integers, every element ...
- LeetCode Single Number I II Python
Single Number Given an array of integers, every element appears twice except for one. Find that sing ...
- [LeetCode] Single Number III 单独的数字之三
Given an array of numbers nums, in which exactly two elements appear only once and all the other ele ...
- [LeetCode] Single Number II 单独的数字之二
Given an array of integers, every element appears three times except for one. Find that single one. ...
- [LeetCode] Single Number 单独的数字
Given an array of integers, every element appears twice except for one. Find that single one. Note:Y ...
- LeetCode Single Number I / II / III
[1]LeetCode 136 Single Number 题意:奇数个数,其中除了一个数只出现一次外,其他数都是成对出现,比如1,2,2,3,3...,求出该单个数. 解法:容易想到异或的性质,两个 ...
- LeetCode:Single Number II
题目地址:here 题目大意:一个整数数组中,只有一个数出现一次,其余数都出现3次,在O(n)时间,O(1)空间内找到这个出现一次的数 对于”只有一个数出现一次,其余数出现2次“的情况,很简单,只要把 ...
- LeetCode Single Number III
原题链接在这里:https://leetcode.com/problems/single-number-iii/ 题目: Given an array of numbers nums, in whic ...
- LeetCode——Single Number II(找出数组中只出现一次的数2)
问题: Given an array of integers, every element appears three times except for one. Find that single o ...
随机推荐
- English trip -- VC(情景课)2 A At school
xu言: Sometimes, I feel very confused. However, there will always be a weak light in a corner to ligh ...
- Java 历史
James Gosling 最初开始 Java 语言项目是在 1991 年的 7 月.Java 被用在他的许多 set-top box 工程中.这个语言最开始的时候被称为 Oka,这个是因为 Jame ...
- Bash and a Tough Math Puzzle CodeForces - 914D (线段树二分)
大意:给定序列, 单点修改, 区间询问$[l,r]$内修改至多一个数后$gcd$能否为$x$ 这题比较有意思了, 要注意到询问等价于$[l,r]$内最多有1个数不为$x$的倍数 可以用线段树维护gcd ...
- html <a>标签介绍
<a href="javascript:void(0)" click="function(){}" />= a 标签样式 一组专门的预定义的 ...
- CAS 服务端数据库认证
CAS-服务端数据库认证 数据认证需要相关的jar包: cas-server-support-jdbc-x.x.x.jar MySQL-connector-Java-x.x.x-bin.jar 修改C ...
- 下拉选择框 Spinner的用法。
代码如下: package com.lixu.xialakuang; import android.app.Activity; import android.content.Context; impo ...
- FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
vue项目 npm run dev 报错 WAIT Compiling...16:36:21 95% emittingFATAL ERROR: CALL_AND_RETRY_LAST Allocati ...
- delphi中TQueue的使用问题
TQueue里存放的是指针,所要存储的内容最好建立在堆上,在pop方法之后释放掉这个空间. 实例代码: MMSQueue:= TQueue.Create; MMSQueue.Push(StrNew(P ...
- IOS语言总结
本文主要介绍和C++不同的地方. 1.类的定义: 一个类有两个文件一个.h还有一个.m文件 #import <Foundation/Foundation.h> @interface MyC ...
- 使用MyEclipse开发Java EE应用:用XDoclet创建EJB 2 Session Bean项目(五)
MyEclipse限时秒杀!活动火热开启中>> [MyEclipse最新版下载] 六.部署到JBoss服务器 1. 右键单击Servers视图,然后选择New>Server,选择您安 ...