-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOddOccuranceArray_66Percent.cpp
More file actions
62 lines (51 loc) · 1.88 KB
/
OddOccuranceArray_66Percent.cpp
File metadata and controls
62 lines (51 loc) · 1.88 KB
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
52
53
54
55
56
57
58
59
60
61
62
// OddOccuranceArrayPrasanth.cpp : Defines the entry point for the console application.
//Score: 66%
#include "stdafx.h"
#include <vector>
#include <iostream>
using namespace std;
int solution(vector<int> &A)
{
int result = 0;
vector<int> B = A;
//cout << "The contents of B Array:" << endl;
int i = 0, j = i+1;
for (int loopcnt = 0; loopcnt <= B.size(); loopcnt++)
{
// cout << B[loopcnt]<<endl;
if (B.size() == 1)
{
result = B[0];
return result;
}
if (B[i] == B[j])
{
B.erase(B.begin() + i);
B.erase(B.begin() + j-1);
i = 0;
j = i+1;
loopcnt = 0;
}
else
{
if (j < B.size() - 1)
{
j = j + 1;
}
else
{
// i = i + 1;
result = B[i];
break;
}
}
}
return result;
}
int main()
{
vector<int> A = { 9,9,9,3,3,9,7,8,8};
int result = solution(A);
cout << "The result is" << result << endl;
return 0;
}