Skip to content

Commit e5b4c21

Browse files
committed
Add C++ solution of problem #2460
1 parent b9b9e0d commit e5b4c21

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

2460/solution.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public:
3+
vector<int> applyOperations(vector<int>& A) {
4+
int n = A.size();
5+
for(int i = 0; i < n - 1; i++) {
6+
if(A[i] == A[i + 1]) {
7+
A[i] *= 2;
8+
A[i + 1] = 0;
9+
}
10+
}
11+
12+
vector<int> ans(n);
13+
for(int i = 0, idx = 0; i < n; i++) {
14+
if(A[i] != 0) {
15+
ans[idx] = A[i];
16+
idx++;
17+
}
18+
}
19+
return ans;
20+
}
21+
};

0 commit comments

Comments
 (0)