Leetcode 136. Single Number
2018-02-08 09:15
399 查看
原题:
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?
解决方法:
a^a=0, a^0=a.所以讲所以数异或即可得答案。
代码:
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?
解决方法:
a^a=0, a^0=a.所以讲所以数异或即可得答案。
代码:
int singleNumber(vector<int>& nums) { int res = 0; for(auto num: nums) res ^= num; return res; }
相关文章推荐
- LeetCode之136. Single Number
- <LeetCode>136. Single Number
- LeetCode解题笔记136 Single Number
- LeetCode: 136. Single Number
- Leetcode刷题记——136. Single Number(单独的数字)
- [LeetCode]136 Single Number
- LeetCode - 136. Single Number
- LeetCode_136-Single Number
- Leetcode_136_Single Number
- leetcode|Single Number(136)
- leetcode 136. Single Number
- 【leetcode】136. Single Number
- LeetCode 136. Single Number
- LeetCode(136) Single Number
- LeetCode(136)Single Number
- LeetCode - 136. Single Number - ( C++ ) - 解题报告 - 位运算思路 xor
- [leetcode]--136. Single Number
- [LeetCode]题解(python):136-Single Number
- [leetcode] 136. Single Number
- Leetcode_Alog.136- Single Number