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. tar.xz文件

    创建或解压tar.xz文件的方法 习惯了 tar czvf 或 tar xzvf 的人可能碰到 tar.xz也会想用单一命令搞定解压或压缩.其实不行 tar里面没有征对xz格式的参数比如 z是针对 g ...

  2. ubuntu下查询网络的常用命令

    1.查看无线路由器(网关)的IP地址 在terminal中输入如下命令,即可查询到当前使用的路由器的IP地址(我电脑是连着一个无线网络还有一个DSL连接): route|grep -i default ...

  3. 纯css隔行显示不同颜色

    通过:nth-child(even) 属性来设置背景色可以使table表格偶数行显示不同颜色::nth-child(odd)设置背景色可以使table表格奇数行显示不同颜色:

  4. 吴裕雄--天生自然 PHP开发学习:魔术常量

    <?php echo '这是第 " ' . __LINE__ . ' " 行'; ?> <?php echo '该文件位于 " ' . __FILE__ ...

  5. PAT Advanced 1067 Sort with Swap(0,*) (25) [贪⼼算法]

    题目 Given any permutation of the numbers {0, 1, 2,-, N-1}, it is easy to sort them in increasing orde ...

  6. mysql字段修改脚本

    -- help_text:帮助说明 -- help_content -- raw USE pro_seal_chip_sell_portal_v1; -- 表修改ALTER TABLE `help_t ...

  7. [Sdoi2013]森林(启发式合并+主席树)

    对于操作1,显然可以使用主席树维护,然后对于一条链(x,y),假设lca为f,根为rt,则(rt,x)+(rt,y)-(rt,f)-(rt,fa[f])即为所求的链,在主席树上直接查询即可,查询方式类 ...

  8. framebuffer 知识点

    设备文件是在/dev/目录下设备文件有主设备号,次设备号.当操作设备文件, 系统会根据设备文件的设备号找到相应的设备驱动(驱动在内核注册时已指定使用的设备号),并调用相应的功能.  open ---& ...

  9. HTMLTestRunner 报告框架使用

    HTMLTestRunner 报告框架使用 file_path = base_path + '/Report/report.html' with open(file_path, 'wb') as f: ...

  10. 分享几个4412开发板新录制的视频,不是VIP也能看

    如果能点个赞就更好啦 iTOP4412开发板介绍https://www.bilibili.com/video/av74453392 iTOP4412开发板系统编程前言https://www.bilib ...