Skip to content

Commit 266ebd8

Browse files
committed
Add C++ solution of problem #3191
1 parent 7170367 commit 266ebd8

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

3191/solution.cpp

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

0 commit comments

Comments
 (0)