Given an array of integers, every element appears twice except for one. Find that single one.Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?

  线性时间完成,不花费多余空间,问题特殊,异或运算就解决了。

public class Solution {
public int singleNumber(int[] nums) {
int result = 0;
for(int num: nums)
{
result^=num;
}
return result;
}
}

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

  10. Leetcode 137. Single Number I/II/III

    Given an array of integers, every element appears twice except for one. Find that single one. 本题利用XO ...

随机推荐

  1. 初学Scala

    由于项目的需要接触了Scala语言,也花了一些时间来了解和学习Scala,今天对学习的Scala进行一个小的总结. 1.What is Scala? Scala的官方网站上给出的解释是: Scala ...

  2. (转发)centos,redhat 系统为php安装memcached扩展

    转自:http://www.itnose.net/detail/6111623.html 1. 通过yum安装 yum -y install memcached #安装完成后执行: memcached ...

  3. iptables基本规则配置(二)

    注释:文章中fg:为示例  红色标记的为命令 在上篇博文中详细讲解了iptables的原理及一些常用命令,这里在简要的说明一下: Linux防火墙包含了2个部分,分别是存在于内核空间的(netfilt ...

  4. VMware下利用ubuntu13.04建立嵌入式开发环境之一

    1.软件准备: (1) VMware网上很多,需要根据自己的需要选择,这里选用的VMware Workstation 9. (2)ubuntu  操作系统,同样根据自己的需要下载系统安装包.这里我选择 ...

  5. 帝国cms怎么调用栏目的别名呢?

    在世界买家网新模板制作过程中,由于栏目名称比较长,用在标题上没有问题,对seo有利,但是在页面上不希望这么长,简单即可,提过提供了栏目别名,如果能调用就方便了, 请留意下面的修改方法 修改后栏目别名使 ...

  6. 第3.2 使用案例1:股票期货stock portfolio 21050917

    As mentioned earlier in the chapter, the first use case revolves around a stock portfolio use case  ...

  7. 颜色代码表#FFFFFF #FF0000 #00FF00 #FF00FF (2015-07-21 10:39)转载

    ▼标签: 颜色代码表 白色 ffffff 红色 ff0000 黑色 000000 it     分类: hht1 白色 #FFFFFF 2 红色 #FF0000 3 绿色 #00FF00 4 蓝色 # ...

  8. ruby on rails 安装

    第一种方案: 1. 下载ruby    Ruby21-x64 2. 1 gem sources --remove http://rubygems.org 2. 2 gem sources -a htt ...

  9. CxImage在VS2010下的配置

    http://blog.csdn.net/youzhuo/article/details/24601621 一.编译Cximage 1.在SourceForge上下载cximage702_full.7 ...

  10. GGXX的卡通渲染实现 真的好变态......

    最近在youtube上看了GDC,学了很多东西,最让我震撼的就是ggxx的卡通渲染了.感慨一下,想要用3D做出二次元的效果,真的不容易.现记录一些要点: 1)不要使用normal map来做cel-s ...