Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 266ebd8

Browse files
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‎

Lines changed: 22 additions & 0 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /