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

45 lines
2.4 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>如果一个由&nbsp;<code>&#39;0&#39;</code><code>&#39;1&#39;</code>&nbsp;组成的字符串,是以一些 <code>&#39;0&#39;</code>(可能没有 <code>&#39;0&#39;</code>)后面跟着一些 <code>&#39;1&#39;</code>(也可能没有 <code>&#39;1&#39;</code>)的形式组成的,那么该字符串是&nbsp;<strong>单调递增&nbsp;</strong>的。</p>
<p>我们给出一个由字符 <code>&#39;0&#39;</code><code>&#39;1&#39;</code>&nbsp;组成的字符串 <font color="#c7254e" face="Menlo, Monaco, Consolas, Courier New, monospace"><span style="caret-color: rgb(199, 37, 78); font-size: 12.600000381469727px; background-color: rgb(249, 242, 244);">s</span></font>,我们可以将任何&nbsp;<code>&#39;0&#39;</code> 翻转为&nbsp;<code>&#39;1&#39;</code>&nbsp;或者将&nbsp;<code>&#39;1&#39;</code>&nbsp;翻转为&nbsp;<code>&#39;0&#39;</code></p>
<p>返回使 <font color="#c7254e" face="Menlo, Monaco, Consolas, Courier New, monospace"><span style="caret-color: rgb(199, 37, 78); font-size: 12.600000381469727px; background-color: rgb(249, 242, 244);">s</span></font>&nbsp;<strong>单调递增&nbsp;</strong>的最小翻转次数。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>s =<strong> </strong>&quot;00110&quot;
<strong>输出:</strong>1
<strong>解释:</strong>我们翻转最后一位得到 00111.
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>s =<strong> </strong>&quot;010110&quot;
<strong>输出:</strong>2
<strong>解释:</strong>我们翻转得到 011111或者是 000111。
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>s =<strong> </strong>&quot;00011000&quot;
<strong>输出:</strong>2
<strong>解释:</strong>我们翻转得到 00000000。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 20000</code></li>
<li><font color="#c7254e" face="Menlo, Monaco, Consolas, Courier New, monospace"><span style="caret-color: rgb(199, 37, 78); font-size: 12.600000381469727px; background-color: rgb(249, 242, 244);">s</span></font> 中只包含字符&nbsp;<code>&#39;0&#39;</code>&nbsp;&nbsp;<code>&#39;1&#39;</code></li>
</ul>
<p>&nbsp;</p>
<p><meta charset="UTF-8" />注意:本题与主站 926&nbsp;题相同:&nbsp;<a href="https://leetcode-cn.com/problems/flip-string-to-monotone-increasing/">https://leetcode-cn.com/problems/flip-string-to-monotone-increasing/</a></p>