Class Solution
java.lang.Object
g1501_1600.s1529_bulb_switcher_iv.Solution
1529 - Minimum Suffix Flips.<p>Medium</p>
<p>You are given a <strong>0-indexed</strong> binary string <code>target</code> of length <code>n</code>. You have another binary string <code>s</code> of length <code>n</code> that is initially set to all zeros. You want to make <code>s</code> equal to <code>target</code>.</p>
<p>In one operation, you can pick an index <code>i</code> where <code>0 <= i < n</code> and flip all bits in the <strong>inclusive</strong> range <code>[i, n - 1]</code>. Flip means changing <code>'0'</code> to <code>'1'</code> and <code>'1'</code> to <code>'0'</code>.</p>
<p>Return <em>the minimum number of operations needed to make</em> <code>s</code> <em>equal to</em> <code>target</code>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> target = “10111”</p>
<p><strong>Output:</strong> 3</p>
<p><strong>Explanation:</strong> Initially, s = “00000”.</p>
<p>Choose index i = 2: “00000” -> “00111”</p>
<p>Choose index i = 0: “00111” -> “11000”</p>
<p>Choose index i = 1: “11000” -> “10111”</p>
<p>We need at least 3 flip operations to form target.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> target = “101”</p>
<p><strong>Output:</strong> 3</p>
<p><strong>Explanation:</strong> Initially, s = “000”.</p>
<p>Choose index i = 0: “000” -> “111”</p>
<p>Choose index i = 1: “111” -> “100”</p>
<p>Choose index i = 2: “100” -> “101”</p>
<p>We need at least 3 flip operations to form target.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> target = “00000”</p>
<p><strong>Output:</strong> 0</p>
<p><strong>Explanation:</strong> We do not need any operations since the initial s already equals target.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>n == target.length</code></li>
<li><code>1 <= n <= 10<sup>5</sup></code></li>
<li><code>target[i]</code> is either <code>'0'</code> or <code>'1'</code>.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
minFlips
-