diff --git a/3191. Minimum Operations to Make Binary Array Elements Equal to One I b/3191. Minimum Operations to Make Binary Array Elements Equal to One I new file mode 100644 index 0000000..981268b --- /dev/null +++ b/3191. Minimum Operations to Make Binary Array Elements Equal to One I @@ -0,0 +1,17 @@ +class Solution { +public: + int minOperations(vector& nums) { + int n = nums.size(); + int count = 0; + for( int x = 0 ; x < n-2 ; x++ ){ + if( nums[ x ] == 0 ){ + nums[ x ] = 1; + nums[ x+1 ] = 1 - nums[ x+1 ]; + nums[ x+2 ] = 1 - nums[ x+2 ]; + count++; + } + } + for( auto i : nums ) if( i == 0 ) return -1; + return count; + } +};