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. idea代理上网

    idea 代理上网 浏览器能够上网,idea无法下载jar 浏览器无法上网则配置浏览器代理 --------- start //------------------------浏览器代理完毕 idea ...

  2. l1 和l2范数的真实意义

    很长时间一直没有明白真实的含义,十一期间补充一下这方面的知识. l0 范数是 ||x||0 = xi (xi不等于0)代表非0数字的个数,[1,2,3,4,5]  非0个数为5,[0,1,2,0,3] ...

  3. 吴裕雄--天生自然 PHP开发学习:MySQL 预处理语句

    <?php $servername = "localhost"; $username = "root"; $password = "admin& ...

  4. PHP实现冒泡排序算法相关案例

    <?php /** * 冒泡排序,先找出一个最大的浮上去,然后再依次找最大的浮上去 */ function mpsort($a = []){ $nCount = count($a); if($n ...

  5. Error:Execution failed for task ':app:preDebugAndroidTestBuild'. > Conflict with dependency

    Error : Execution failed for task ’ :app: preDebugAndroidTestBuild’.Conflict with dependency ‘com.an ...

  6. MySQL--mysqldump(数据导出工具)

    mysqldump 客户端工具用来备份数据库或在不同数据库之间进行数据迁移.备份内容包含创建表或装载表的 SQL 语句.mysqldump 目前是 MySQL 中最常用的备份工具. 有 3 种方式来调 ...

  7. [HAOI2018]苹果树(组合数学)

    首先有个很奇妙而且很有用的性质:每个二叉树对应唯一的中序遍历,然后每个二叉树出现概率相同.所以n个节点的二叉树形态是n!种(题目中说了*n!已经是提示了),对每种方案求和即可得到期望.令f[i]表示i ...

  8. h5 移动端在阻止touchstart的默认事件时报错

    h5 移动端在阻止touchstart的默认事件时报错 解决办法, 可以添加 *{ touch-action: none;}即可消除错误

  9. php安装swoole2.1.2

    准备环境: cos7.2  &   php 7.1.7 1.www.swoole.com找到对应版本2.使用git clone或则 wget 命令(下载后需解压)进行下载3.在swoole目录 ...

  10. 吴裕雄--天生自然 JAVA开发学习:继承

    class 父类 { } class 子类 extends 父类 { } public class Penguin { private String name; private int id; pub ...