Given 2*n + 1 numbers, every numbers occurs twice except one, find it.

Have you met this question in a real interview?

Yes
Example

Given [1,2,2,1,3,4,3], return 4

Challenge

One-pass, constant extra space.

LeetCode上的原题,请参见我之前的博客Single Number

class Solution {
public:
int singleNumber(vector<int>& nums) {
int res = ;
for (auto num : nums) res ^= num;
return res;
}
};

[LintCode] Single Number 单独的数字的更多相关文章

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

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

  2. [LeetCode] 136. Single Number 单独数

    Given a non-empty array of integers, every element appears twice except for one. Find that single on ...

  3. LintCode: Single Number

    C++ (1)异或操作 3^3=0 (2)for (auto &i : Obejuct) {} class Solution { public: /** * @param A: Array o ...

  4. 136. Single Number唯一的数字

    [抄题]: Given an array of integers, every element appears twice except for one. Find that single one. ...

  5. Lintcode: Single Number III

    Given 2*n + 2 numbers, every numbers occurs twice except two, find them. Example Given [1,2,2,3,4,4, ...

  6. LintCode: Single Number II

    一篇解析比较详细的文章:http://www.acmerblog.com/leetcode-single-number-ii-5394.html C++ 解法(1) 求出每个比特位的数目,然后%3,如 ...

  7. [LeetCode] Missing Number 丢失的数字

    Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...

  8. [LeetCode] 268. Missing Number ☆(丢失的数字)

    转载:http://www.cnblogs.com/grandyang/p/4756677.html Given an array containing n distinct numbers take ...

  9. leetcode 136. Single Number 、 137. Single Number II 、 260. Single Number III(剑指offer40 数组中只出现一次的数字)

    136. Single Number 除了一个数字,其他数字都出现了两遍. 用亦或解决,亦或的特点:1.相同的数结果为0,不同的数结果为1 2.与自己亦或为0,与0亦或为原来的数 class Solu ...

随机推荐

  1. js高级群的一些整理6月

    https://github.com/the5fire/backbonejs-learning-note/blob/master/chapters/01-hello-backbonejs.rst Ba ...

  2. 【poj2096】Collecting Bugs

    题目描述 Ivan is fond of collecting. Unlike other people who collect post stamps, coins or other materia ...

  3. HQL常用的查询语句

    摘录自某人,比较有用,比较全. // HQL: Hibernate Query Language. // 特点: // >> 1,与SQL相似,SQL中的语法基本上都可以直接使用. // ...

  4. 【强烈推荐】利用NAT、Host-Only双虚拟网卡,实现Virtual Box中CentOS6.3联网

    问题背景: 先前都是在Virtual Box中以“网络共享”方式,让里面的Linux虚拟机Host-Only方式联网,参考如下: Virtual Box下配置Host-Only联网方式详解 但最近被公 ...

  5. ReactiveCocoa源码拆分解析(四)

    (整个关于ReactiveCocoa的代码工程可以在https://github.com/qianhongqiang/QHQReactive下载) 上一章节简要的说明了如何实现的热信号.但是像那么写, ...

  6. FZU 2112 并查集、欧拉通路

    原题:http://acm.fzu.edu.cn/problem.php?pid=2112 首先是,票上没有提到的点是不需要去的. 然后我们先考虑这个图有几个连通分量,我们可以用一个并查集来维护,假设 ...

  7. php中几个字符串替换函数详解

    在php中字符替换函数有几个如有:str_replace.substr_replace.preg_replace.preg_split.str_split等函数,下面我来给大家总结介绍介绍. 一.st ...

  8. poj 1141

    简单的dp 忘了\n,调了半天(目测不是第一次了) 直接贴代码: #include<cstdio> #include<cstring> using namespace std; ...

  9. liunx中计算机壳层

    什么是shell?shell是用C语言编写的程序.既是一种命令语言,又是一种程序设计语言.shell是一种应用程序,这个应用程序提供一个界面,用户通过这个界面访问系统内核的服务.在计算机科学中,She ...

  10. ID属性值为小数

    获取带有.的id值 <h1 id="123.45">dom对象</h1> <script> $('#123\\.45').attr('id') ...