# [leetcode] 136. Single Number

136 Single Number

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?

class Solution {
public:
int singleNumber(vector<int>& nums) {
sort(nums.begin(),nums.end());
int n = 0;

for(int i=0;i!=nums.size();++i)
{
if (i+1==nums.size())
{
n = nums[i];
break;
}
if(nums[i]==nums[i+1]){
i++;
}
else{
n = nums[i];
}
}
return n;
}
};

class Solution {
public:
int singleNumber(vector<int>& nums) {
int len = nums.size();
int re = 0 ;
for (int i=0; i<len; i++)
{
res ^= nums[i];
}
return res;
}
};  

#### LeetCode 136：Single Number I

2015-05-12 19:51:37

#### 136. Single Number [medium] (Python)

2016-07-29 14:30:31

#### python--leetcode136. Single Number

2017-10-08 19:54:07

#### LeetCode 136. Single Number 题解（C++）

2016-09-29 12:07:25

#### 【LeetCode-面试算法经典-Java实现】【136-Single Number（只出现一次的数字）】

2015-08-18 06:18:14

#### LeetCode[136] Single Number 位运算异或，HashMap（Java）

2015-05-29 10:28:50

#### LeetCode || Single Number II

2014-04-09 23:35:07

#### LeetCode 136. 只出现一次的数字 Python

2018-05-30 16:12:19

#### LeetCode-136. Single Number (Java)

2017-06-10 13:47:01