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的更多相关文章

  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(找出数组中只出现一次的数2)

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

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

    Given 2*n + 1 numbers, every numbers occurs twice except one, find it. Have you met this question in ...

  7. 【LeetCode】Single Number I & II & III

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

  8. LeetCode 【Single Number I II III】

    Given an array of integers, every element appears twice except for one. Find that single one. 思路: 最经 ...

  9. 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 ...

随机推荐

  1. 【原】MAC显示隐藏文件夹命令

    显示隐藏文件夹 1. 显示:defaults write com.apple.finder AppleShowAllFiles -bool true 第一步:命令行执行上述命令:

  2. iOS学习31之UITableVIewCell自定义

    1. 自定义Cell 1> 为什么要自定义Cell UITableView 中系统的Cell共提供了四种默认样式,  分别是: UITableViewCellStyleDefault UITab ...

  3. Prerequisites?[HDU1144]

    Prerequisites?Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...

  4. 跳转页面&回到上一页

    1.php <?php header('Location:2.php'); //echo不能在其前面 echo '1'; 2.js <?php echo '2'; echo '<me ...

  5. Oracle存储过程中临时表的使用技巧

    一.Oracle临时表知识 在Oracle中,临时表分为SESSION(会话级).TRANSACTION(事务级)两种,SESSION级的临时表数据在整个SESSION都存在,直到结束此次SESSIO ...

  6. QWord2vec:word2vec移植版+GUI

    序 Word2Vec原生是不支持Windows的,索性就用Qt移植了一下. 大概做了下面几件事. ①替换LinuxAPI的pthread为QThread. ②取消了posix_memalign(),内 ...

  7. POJ 3320 (尺取法+Hash)

    题目链接: http://poj.org/problem?id=3320 题目大意:一本书有P页,每页有个知识点,知识点可以重复.问至少连续读几页,使得覆盖全部知识点. 解题思路: 知识点是有重复的, ...

  8. 解决JS浮点数(小数)计算加减乘除的BUG

    在JavaScript中输出下面这些数值(注意不能作为字符串输出):0.1000000000000000000000000001(28位小数).0.10000000000000000000000000 ...

  9. 关于url

    URL即统一资源定位器用于定位万维网上的文档或其他数据,URL 可以由单词组成,比如 “www.baidu.com”,或者是因特网协议(IP)地址:192.168.x.xxx.大多数人在网上冲浪时,会 ...

  10. C# 委托和Lambda---基础

    [委托]是一个类可以把一个方法当作另一个方法的参数使用. 声明委托:delegate string 委托名(参数列表);//跟定义方法一样,只是没有方法体,必须使用关键字delegate使用委托的函数 ...