Skip to content

Commit 0bf8db9

Browse files
Create 3191_Minimum_Operations_to_make_Binary_Element_equal_to_OneI.java
1 parent 2ee0e4b commit 0bf8db9

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//Problem Number: 3191
2+
3+
// Minimum Operation to make binary element equal to One I.
4+
5+
class Solution {
6+
public int minOperations(int[] nums) {
7+
final int n = nums.length;
8+
int ans = 0;
9+
10+
for (int i = 0; i + 2 < n; ++i)
11+
if (nums[i] == 0) {
12+
nums[i + 1] ^= 1;
13+
nums[i + 2] ^= 1;
14+
++ans;
15+
}
16+
17+
return nums[n - 1] == 0 || nums[n - 2] == 0 ? -1 : ans;
18+
}
19+
}

0 commit comments

Comments
 (0)