Leetcode# 136. Single Number(出现一次的数&异或)
来源:互联网 发布:淘宝怎么不能找人代付 编辑:程序博客网 时间:2024/05/18 15:51
Given an 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?
题意是说给你一个数组,只有一个数是出现一次的,其余数都出现两次,让你输入出现一次的数。
异或大法:相同为0,相反为原数
例如:a=1,b=1,c=9
d=a^b^c=9
我的代码:
class Solution {public: int singleNumber(vector<int>& nums) { int res=0; for(int i=0;i<nums.size();i++) res^=nums[i]; return res; }};
阅读全文
1 0
- Leetcode# 136. Single Number(出现一次的数&异或)
- Single Number 数组找只出现一次的数@LeetCode
- Single Number III 两个不同的数出现一次,其余两次,异或
- 136. Single Number | 找出那个只出现一次的数
- Single Number II --出现一次的数(重)
- LeetCode 136 Single Number(只出现一次的数字)
- 136.Single Number (数组中只出现一次的数)
- 数组中出现一次的两个数 leetcode Single Number III
- 找出数组中只出现一次的数(single number )
- 136 Single Number 找到只出现一次的数
- 找出两个只出现一次的数(其它都出现两次)Single Number III
- 寻找只出现一次的数字(LeetCode: Single Number II)
- Leetcode 136 Single Number 仅出现一次的数字
- Leetcode 137 Single Number II 仅出现一次的数字
- Leetcode 260 Single Number III 仅出现一次的数字
- LeetCode 136 Single Number 出现一次的数字
- [LeetCode]Single Number 异或的妙用
- 260. Single Number III (找到数组中仅出现一次的两个数)
- java设计模式之命令模式
- Zookeeper + ActiveMQ 集群整合
- 中文乱码在java中URLEncoder.encode方法要调用两次解决
- 反射中常用的一些方法
- Python2.7 图片合成gif
- Leetcode# 136. Single Number(出现一次的数&异或)
- jzoj 3928_射击_堆
- web配置文件属性metadata-complete讲解
- 欢迎使用CSDN-markdown编辑器
- Android Library工程switch case中使用 R.id.x报错
- 百度APi
- Android BLE虚拟设备端
- light oj 1341 Aladdin and the Flying Carpet
- 2017西安交大ACM小学期 美妙音乐[差分KMP匹配]