-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path80_remove_duplicates_2.cpp
More file actions
40 lines (33 loc) · 1.05 KB
/
80_remove_duplicates_2.cpp
File metadata and controls
40 lines (33 loc) · 1.05 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
#include <vector> // For std::vector
#include <iterator> // For std::make_move_iterator
#include <algorithm> // For std::copy (if needed)
class Solution {
public:
int removeDuplicates(std::vector<int>& nums) {
int tempIndx = 0;
std::vector<int> temp(nums.size(),0);
int tempVal = nums.at(0);
std::vector<int> temp2;
for(int i = 0; i < nums.size(); i++){
if(tempVal == nums.at(i)) {
temp.at(tempIndx)++;
} else {
tempIndx = i;
temp.at(tempIndx)++;
tempVal = nums.at(i);
}
}
for(int i = 0; i < temp.size(); i++){
if(temp.at(i) != 0) {
if(temp.at(i)==1) {
temp2.push_back(nums.at(i));
} else if(temp.at(i)>=2) {
temp2.push_back(nums.at(i));
temp2.push_back(nums.at(i));
}
}
}
nums = temp2;
return temp2.size();
}
};