#3191
Minimum Operations to Make Binary Array Elements Equal to One I
pupil · 440 · lc medium +26 · 80.4% accepted · 674 likes · top 92%
Description
You are given a binary array nums.
You may apply any number of operations (possibly zero):
- Select any 3 consecutive elements and toggle all of their values (0 becomes 1, 1 becomes 0).
Return the minimum number of operations required so that every element in nums equals 1. Return -1 if it is not possible.
Code
1
2
3