leetcode 136 Single Number bBt Option
Linked Url:https://leetcode.com/problems/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 :
Input: [,,]
Output: 1
Example :
Input: [,,,,]
Output:
solution:
The method is xor option, principles is : 0 xor 0 = 0; 0 xor 1 = 1;any num xor itself = 0,so we pass the array and xor its elements all,so the result which is we want.
Ac code follow:
class Solution {
public:
int singleNumber(vector<int>& nums) {
int res = nums[];
for(int i = ;i < nums.size();++i)
res = nums[i]^res;
return res;
}
};
leetcode 136 Single Number bBt Option的更多相关文章
- 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(只出现一次的数字)
- LeetCode 136. Single Number C++ 结题报告
136. Single Number -- Easy 解答 相同的数,XOR 等于 0,所以,将所有的数字 XOR 就可以得到只出现一次的数 class Solution { public: int ...
- 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(仅仅出现一次的数字)
翻译 给定一个整型数组,除了某个元素外其余元素均出现两次. 找出这个仅仅出现一次的元素. 备注: 你的算法应该是一个线性时间复杂度. 你能够不用额外空间来实现它吗? 原文 Given an array ...
- [LeetCode] 136. Single Number 单独数
Given a non-empty array of integers, every element appears twice except for one. Find that single on ...
- LeetCode 136. Single Number (落单的数)
Given an array of integers, every element appears twice except for one. Find that single one. Note:Y ...
- Leetcode 136 Single Number 仅出现一次的数字
原题地址https://leetcode.com/problems/single-number/ 题目描述Given an array of integers, every element appea ...
- LeetCode - 136. Single Number - ( C++ ) - 解题报告 - 位运算思路 xor
1.题目大意 Given an array of integers, every element appears twice except for one. Find that single one. ...
随机推荐
- WPF 数据模板使用值转换器
<Window x:Class="CollectionBinding.MainWindow" xmlns="http://schemas.micros ...
- win10 uwp 如何判断一个对象被移除
原文:win10 uwp 如何判断一个对象被移除 有时候需要知道某个元素是否已经被移除,在优化内存的时候,有时候无法判断一个元素是否在某个地方被引用,就需要判断对象设置空时是否被回收. 本文告诉大家一 ...
- dotnet core 跨平台编译发布
vs2017 建立的项目,在项目目录 ,执行 dotnet publish -r ubuntu.15.04-x64 dotnet publish -r linux-x64 dotnet publish ...
- WPF应用App.Config文件的保存路径
App.Config文件有更改后,自动会保存到以下路径: C:\Users\你的系统用户名\AppData\Local\你的应用名\
- winform子容器随父容器的变化设置
在设计winform窗体时,因为会很少去调整窗体的大小,这时子控件就会出很尴尬的情况, 通过查看空间的属性,发现有这样两个属性,dock和anchor.这里主要说anchor,官方 解释没太看懂,我的 ...
- 浅谈浏览器http的缓存机制 good
http://www.cnblogs.com/vajoy/p/5341664.html
- C++&Win32写的空当接龙
上学期做课程设计,老师让我做windows自带的空当接龙游戏,写了一个礼拜,完全仿windows的呵呵.不过也不全一样,有一些细节一直没有时间弄,没办法最近比较懒... 与windows下的相比,我做 ...
- foruok安晓辉的《程序员,你好哇》,都很不错
http://blog.csdn.net/foruok 买书: http://item.jd.com/11904166.html
- 浅谈js闭包(closure)
相信很多从事js开发的朋友都或多或少了解一些有关js闭包(closure)的知识. 本篇文章是从小编个人角度,简单地介绍一下有关js闭包(closure)的相关知识.目的是帮助一些对js开发经验不是很 ...
- orm单表操作
二.orm简介 ORM:object relation mapping (ORM是“对象-关系-映射”的简称) MVC或者MVC框架中包括一个重要的部分,就是ORM,它实现了数据模型与数据库的解耦, ...