-
Notifications
You must be signed in to change notification settings - Fork 0
/
136.cpp
51 lines (43 loc) · 999 Bytes
/
136.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <vector>
#include <map>
using namespace std;
class Solution2 {
public:
int singleNumber(vector<int>& nums) {
map<int,int> temp;
map<int,int>::iterator ite;
int len=nums.size();
for(int i=0;i<len;i++)
{
ite=temp.find(nums[i]);
if(ite==temp.end())
temp.insert(pair<int,int>(nums[i],0));
else
ite->second++;
}
for(ite=temp.begin();ite!=temp.end();ite++)
{
if(ite->second==0)
return ite->first;
}
}
};
class Solution {
public:
int singleNumber(vector<int>& nums) {
int len=nums.size();
if(len==0)
return 0;
int res=nums[0];
for(int i=1;i<len;i++)
{
res=res^nums[i];
}
return res;
}
};
int main()
{
return 0;
}