[LC] 136. Single Number
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的更多相关文章
- leetcode 136. Single Number 、 137. Single Number II 、 260. Single Number III(剑指offer40 数组中只出现一次的数字)
136. Single Number 除了一个数字,其他数字都出现了两遍. 用亦或解决,亦或的特点:1.相同的数结果为0,不同的数结果为1 2.与自己亦或为0,与0亦或为原来的数 class Solu ...
- LeetCode 136. Single Number C++ 结题报告
136. Single Number -- Easy 解答 相同的数,XOR 等于 0,所以,将所有的数字 XOR 就可以得到只出现一次的数 class Solution { public: int ...
- leetcode 136 Single Number, 260 Single Number III
leetcode 136. Single Number Given an array of integers, every element appears twice except for one. ...
- LeetCode 136. Single Number(只出现一次的数字)
LeetCode 136. Single Number(只出现一次的数字)
- 136. Single Number - LeetCode
Question 136. Single Number Solution 思路:构造一个map,遍历数组记录每个数出现的次数,再遍历map,取出出现次数为1的num public int single ...
- 136. Single Number唯一的数字
[抄题]: Given an array of integers, every element appears twice except for one. Find that single one. ...
- 136. Single Number唯一的一个只出现了一次的数字
[抄题]: Given a non-empty array of integers, every element appears twice except for one. Find that sin ...
- 【LeetCode】136. Single Number (4 solutions)
Single Number Given an array of integers, every element appears twice except for one. Find that sing ...
- LeetCode Problem 136:Single Number
描述:Given an array of integers, every element appears twice except for one. Find that single one. Not ...
随机推荐
- 面试准备 HTTP协议
http协议的主要特点 简单快速 //某个资源是固定的 (统一资源符)UII 灵活 //http头部有个数据类型,完成不同数据类型的传输 无连接 //链接一次就会断开 无状态 //客户端和服务端 ...
- torch基础学习
目录 Pytorch Leture 05: Linear Rregression in the Pytorch Way Logistic Regression 逻辑回归 - 二分类 Lecture07 ...
- 03 Mybatis:01.Mybatis课程介绍及环境搭建&&02.Mybatis入门案例
mybatis框架共四天第一天:mybatis入门 mybatis的概述 mybatis的环境搭建 mybatis入门案例 -------------------------------------- ...
- UML-领域模型-准则
1.是否使用工具维护模型? 在白板上画完草图后,整理到UML工具里去 2.模型中是否要包含“票据”? 不包含,因为,票据用于退货,而本次迭代不涉及退货所以不需要体现. 总结:概念一定在本次迭代需求内的 ...
- Random Access Iterator
Random Access Iterator 树型概率DP dp[u]代表以当前点作为根得到正确结果的概率 将深度最深的几个点dp[u]很明显是1 然后很简单的转移 有k次,但我们要先看一次的情况,然 ...
- 使用pythonnet调用halcon脚本
最近的项目中遇到了使用python程序结合不同部分,其中包括使用halcon处理拍摄到的图像. halcon本身提供了c++与.NET的开发库,但无python库,网上有pyhalcon之类的库,但功 ...
- 安装chrome并设置默认主页
chrome 版本 https://support.google.com/chrome/a/answer/187948?hl=en&ref_topic=2936229
- python tricks 01
01: 考察range/sort/lambda 对以下数据进行排序 原数据: [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5] 目标数据: [0, -1, 1, -2, 2 ...
- 关于前端Dom的总结
简介 DOM (Document Object Model) 文档对象模型 DOM思想使用节点树(node tree)的概念来描述一个HTML页面,页面中的每一个元素.属性.文本都被认为是节点.此外, ...
- \_\_str\_\_和\_\_repr\_\_
目录 __str__和__repr__ 一.__str__ 二.repr __str__和__repr__ 一.__str__ 打印时触发 class Foo: pass obj = Foo() pr ...