Leetcode Single Number
2015-05-18 19:28
253 查看
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?
一般的做法是统计每个数值出现的次数,找到那个出现一次的,但是会超时,于是出现用位运算之(异或运算)
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
一般的做法是统计每个数值出现的次数,找到那个出现一次的,但是会超时,于是出现用位运算之(异或运算)
class Solution { public: int singleNumber(vector<int>& nums) { int result = 0; for (int i=0; i<nums.size(); i++) { result = result ^ nums[i]; } return result; } };
相关文章推荐
- LeetCode ---- Single Number (Java/Lua 实现)
- Single Number--LeetCode
- LeetCode:Single Number
- [LeetCode]Single Number
- LeetCode:Single Number
- Leetcode 136 Single Number
- [leetcode] Single Number
- LeetCode:Single Number
- LeetCode刷题笔录 Single Number
- 【LeetCode从零单刷】Single Number
- [leetcode] 136 single number
- 【LeetCode】Single Number
- leetcode[136] Single Number
- leetcode第136题-Single Number
- LeetCode-Easy刷题(31) Single Number
- leetcode: (136) Single Number
- LeetCode 136. Single Number
- LeetCode-Single Number
- Leetcode:Single Number
- 【Leetcode】Single Number (Bit Manipulation)