1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/将字符串翻转到单调递增 [flip-string-to-monotone-increasing].html

41 lines
1.2 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>如果一个二进制字符串,是以一些 <code>0</code>(可能没有 <code>0</code>)后面跟着一些 <code>1</code>(也可能没有 <code>1</code>)的形式组成的,那么该字符串是 <strong>单调递增 </strong>的。</p>
<p>给你一个二进制字符串 <code>s</code>,你可以将任何 <code>0</code> 翻转为 <code>1</code> 或者将 <code>1</code> 翻转为 <code>0</code></p>
<p>返回使 <code>s</code> 单调递增的最小翻转次数。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>s = "00110"
<strong>输出:</strong>1
<strong>解释:</strong>翻转最后一位得到 00111.
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>s = "010110"
<strong>输出:</strong>2
<strong>解释:</strong>翻转得到 011111或者是 000111。
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>s = "00011000"
<strong>输出:</strong>2
<strong>解释:</strong>翻转得到 00000000。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 10<sup>5</sup></code></li>
<li><code>s[i]</code><code>'0'</code><code>'1'</code></li>
</ul>