-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2216.cpp
33 lines (31 loc) · 805 Bytes
/
2216.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
class Solution {
public:
int minDeletion(vector<int>& nums) {
int cnt = 0;
while(1){
bool ok = false;
int flag = 0;
for(int i = 0; i < nums.size(); i++){
if(i + 1 < nums.size() && (i - flag) % 2 == 0 && nums[i] == nums[i + 1]){
nums[i] = -1;
cnt++; flag++;
ok = true;
}
}
vector<int>vec;
for(auto x: nums){
if(x != -1){
vec.push_back(x);
}
}
nums = vec;
if(!ok){
break;
}
}
if(nums.size() % 2 == 0){
return cnt;
}
return cnt + 1;
}
};