less than 1 minute read

You are given an integer list nums containing 0s and 1s. Consider an operation where we pick an index i in nums and flip i as well as all numbers to the right of i. Return the minimum number of operations required to make nums contain all 0s.

Constraints

  • n ≤ 100,000 where n is the length of nums.

https://binarysearch.com/problems/Flip-to-Zeros

Examples

Example 1

Input

  • nums = [1, 1, 0]

Output

  • answer = 2

Explanation

We can flip at index 0 to get [0, 0, 1] and then flip at index 2 to get [0, 0, 0]

Solution

Categories:

Updated:

Leave a comment