Given a non-empty 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?

Example 1:

Input: [2,2,1]
Output: 1

Example 2:

Input: [4,1,2,1,2]
Output: 4
class Solution {
public int singleNumber(int[] nums) {
int res = 0;
for (int num : nums) {
res ^= num;
}
return res;
}
}

[LC] 136. Single Number的更多相关文章

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

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

  2. LeetCode 136. Single Number C++ 结题报告

    136. Single Number -- Easy 解答 相同的数,XOR 等于 0,所以,将所有的数字 XOR 就可以得到只出现一次的数 class Solution { public: int ...

  3. leetcode 136 Single Number, 260 Single Number III

    leetcode 136. Single Number Given an array of integers, every element appears twice except for one. ...

  4. LeetCode 136. Single Number(只出现一次的数字)

    LeetCode 136. Single Number(只出现一次的数字)

  5. 136. Single Number - LeetCode

    Question 136. Single Number Solution 思路:构造一个map,遍历数组记录每个数出现的次数,再遍历map,取出出现次数为1的num public int single ...

  6. 136. Single Number唯一的数字

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

  7. 136. Single Number唯一的一个只出现了一次的数字

    [抄题]: Given a non-empty array of integers, every element appears twice except for one. Find that sin ...

  8. 【LeetCode】136. Single Number (4 solutions)

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

  9. LeetCode Problem 136:Single Number

    描述:Given an array of integers, every element appears twice except for one. Find that single one. Not ...

随机推荐

  1. 将微服务注册到Euraka

    1.添加依赖 <dependency> <groupId>org.springframework.cloud</groupId> <artifactId> ...

  2. SeetaFaceEngine系列3:Face Identification编译和使用

    前面两篇介绍了怎样编译SeetaFace的前两部分,现在就来讲下第三部分Face Identification的编译和使用. 其实,步骤基本上是一直的,如下: 1.新建一个空的DLL工程: 2.修改配 ...

  3. 自定义的listbox支持拖放

    unit unit2; interface uses Classes, Controls, StdCtrls; type TListBox2 = class(TCustomListBox) prote ...

  4. Nginx模块-ngx_http_mirror_module-流量复制【转】

    Nginx流量复制# 需求# 将生产环境的流量拷贝到预上线环境或测试环境,这样做有很多好处,比如: 可以验证功能是否正常,以及服务的性能: 用真实有效的流量请求去验证,又不用造数据,不影响线上正常访问 ...

  5. Python opencv计算批量图片的BGR各自的均值

    #coding:utf-8 #第一种方式 很慢很慢 自己写的如何计算均值 ''' import cv2 import os def access_pixels(frame): print(frame. ...

  6. 论文:利用深度强化学习模型定位新物体(VISUAL SEMANTIC NAVIGATION USING SCENE PRIORS)

    这是一篇被ICLR 2019 接收的论文.论文讨论了如何利用场景先验知识 (scene priors)来定位一个新场景(novel scene)中未曾见过的物体(unseen objects).举例来 ...

  7. 大言不惭 swank? talk about sth or speak too confidently cán,意思是指说大话而毫不感到难为情。出自《论语·宪问》:“子曰:‘其言之不怍,则为之也难。’”宋·朱熹注:“大言不惭,则无必为之志,而不自度其能否也。欲践其言,其不难哉!” 是不是类似于 swank?

    大言不惭 swank? talk about sth or speak too confidently cán,意思是指说大话而毫不感到难为情.出自<论语·宪问>:“子曰:‘其言之不怍,则 ...

  8. 四、Shell脚本高级编程实战第四部

    一.比较两个数的大小 #!/bin/shread -p "Pls input two num:" a b[ -z "$a" ] || [ -z "$b ...

  9. PANIC: ANDROID_SDK_HOME is defined but could not find Nexus_5_API_23.ini file in $ANDROID_SDK_HOME\

    运行模拟器总是出现这个错误 后来把系统环境变量中的ANDROID_SDK_HOME 删掉就好了 我去,好神奇的操作

  10. shell脚本中的条件测试if中的-z到-d的意思

    文件表达式 if [ -f  file ]    如果文件存在if [ -d ...   ]    如果目录存在if [ -s file  ]    如果文件存在且非空 if [ -r file  ] ...