(lleetcode)Single Number
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?
1)使用map
class Solution {
public:
int singleNumber(vector<int>& nums) {
unordered_map<int,int> ret;
int i =;
while(i < nums.size())
{
ret[nums[i]]++;
i++;
}
for(unordered_map<int,int>::iterator it = ret.begin();it != ret.end(); ++it)
{
if(it->second == )
{
return it->first;break;
}
}
}
};
(lleetcode)Single Number的更多相关文章
- [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(找出数组中只出现一次的数2)
问题: Given an array of integers, every element appears three times except for one. Find that single o ...
- [LintCode] Single Number 单独的数字
Given 2*n + 1 numbers, every numbers occurs twice except one, find it. Have you met this question in ...
- 【LeetCode】Single Number I & II & III
Single Number I : Given an array of integers, every element appears twice except for one. Find that ...
- LeetCode 【Single Number I II III】
Given an array of integers, every element appears twice except for one. Find that single one. 思路: 最经 ...
- Add Digits, Maximum Depth of BinaryTree, Search for a Range, Single Number,Find the Difference
最近做的题记录下. 258. Add Digits Given a non-negative integer num, repeatedly add all its digits until the ...
随机推荐
- BZOJ4379 : [POI2015]Modernizacja autostrady
两遍树形DP求出每个点开始往上往下走的前3长路以及每个点上下部分的直径. 枚举每条边断开,设两边直径分别为$A,B$,则: 对于第一问,连接两边直径的中点可得直径为$\max(A,B,\lfloor\ ...
- 使用 Git 和 Visual Studio Online 进行版本控制
参考资料: 在开发计算机上设置 Git(配置.创建.克隆.添加) 关于 Git 和 Visual Studio Online 是什么请自行百度 转载请注明来源: http://www.cnblogs. ...
- ACM Minimum Inversion Number 解题报告 -线段树
C - Minimum Inversion Number Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d &a ...
- [题解+总结]NOIP2013-2014提高组题目浅析
1.前言 迎接NOIP的到来...在这段闲暇时间,决定刷刷水题.这里只是作非常简单的一些总结. 2.NOIP2014 <1> 生活大爆炸之石头剪刀布(模拟) 这是一道考你会不会编程的题目. ...
- Android -- TextView、button方法详解(1)
1.TextView常规方法 TextView myTextView=null; //声明变量 myTextView=(TextView)findViewById(R.id.myTextView); ...
- OLTP与OLAP的介绍
OLTP与OLAP的介绍 数据处理大致可以分成两大类:联机事务处理OLTP(on-line transaction processing).联机分析处理OLAP(On-Line Analytical ...
- Hibernate映射一对多双向关联关系及部门关联属性
一对多双向关联关系:(Dept/Emp的案例) 既可以根据在查找部门时根据部门去找该部门下的所有员工,又能在检索员工时获取某个员工所属的部门. 步骤如下: 1.构建实体类(部门实体类加set员工集合) ...
- C++ substr() 和 Java substring() 区别
Java和C++中都有关于子字符串的操作,C++中是substr(),Java中是substring(),两者的用法上稍有些区别,首先针对只有一个参数的情况: s.substr(start) 和 s. ...
- VTK GetScalarPointer() and GetScalarComponentAsFloat() not work
I am using VTK 5.10.1 with VS 2010, and the following example does not work on my machine: http://ww ...
- HTML5标签简化写法
基本页面格式 <!DOCTYPE> <html> <head> <meta charset="utf-8" /> <title ...