-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path126.cpp
More file actions
46 lines (32 loc) · 844 Bytes
/
Copy path126.cpp
File metadata and controls
46 lines (32 loc) · 844 Bytes
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
#include <bits/stdc++.h>
using namespace std;
int singleNumber(vector<int>& nums) {
int n = nums.size();
int a = 0;
sort(nums.begin(), nums.end());
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
if(nums[i]==nums[j]&&j<n-1){
i=j+1;}
else {a=nums[i];return a;}
}
}
// int i =0;
// while(i<n){
// int j=i;
// for(j=i;j<n && nums[j]==nums[i];j++){}
// if(i==j-1){
// }
// }
}
int main(){
vector<int> nums;
nums.push_back(4);
nums.push_back(4);
nums.push_back(1);
nums.push_back(1);
nums.push_back(1);
nums.push_back(4);
nums.push_back(2);
cout<<singleNumber(nums);
}