Skip to content

Commit ccdce67

Browse files
authored
Create 3191. Minimum Operations to Make Binary Array Elements Equal t… (#745)
2 parents 22980ec + ea2289a commit ccdce67

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public:
3+
int minOperations(vector<int>& nums) {
4+
int n = nums.size();
5+
int count = 0;
6+
for( int x = 0 ; x < n-2 ; x++ ){
7+
if( nums[ x ] == 0 ){
8+
nums[ x ] = 1;
9+
nums[ x+1 ] = 1 - nums[ x+1 ];
10+
nums[ x+2 ] = 1 - nums[ x+2 ];
11+
count++;
12+
}
13+
}
14+
for( auto i : nums ) if( i == 0 ) return -1;
15+
return count;
16+
}
17+
};

0 commit comments

Comments
 (0)