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)/修改后的最大二进制字符串 [maximum-binary-string-after-change].html
2022-03-29 12:43:11 +08:00

50 lines
1.8 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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>binary</code> ,它仅有 <code>0</code> 或者 <code>1</code> 组成。你可以使用下面的操作任意次对它进行修改:</p>
<ul>
<li>操作 1 :如果二进制串包含子字符串 <code>"00"</code> ,你可以用 <code>"10"</code> 将其替换。
<ul>
<li>比方说, <code>"<strong>00</strong>010" -> "<strong>10</strong>010"</code></li>
</ul>
</li>
<li>操作 2 :如果二进制串包含子字符串 <code>"10"</code> ,你可以用 <code>"01"</code> 将其替换。
<ul>
<li>比方说, <code>"000<strong>10</strong>" -> "000<strong>01</strong>"</code></li>
</ul>
</li>
</ul>
<p>请你返回执行上述操作任意次以后能得到的 <strong>最大二进制字符串</strong> 。如果二进制字符串 <code>x</code> 对应的十进制数字大于二进制字符串 <code>y</code> 对应的十进制数字,那么我们称二进制字符串<em> </em><code>x</code><em> </em>大于二进制字符串<em> </em><code>y</code><em> </em></p>
<p> </p>
<p><strong>示例 1</strong></p>
<pre>
<b>输入:</b>binary = "000110"
<b>输出:</b>"111011"
<b>解释:</b>一个可行的转换为:
"0001<strong>10</strong>" -> "0001<strong>01</strong>"
"<strong>00</strong>0101" -> "<strong>10</strong>0101"
"1<strong>00</strong>101" -> "1<strong>10</strong>101"
"110<strong>10</strong>1" -> "110<strong>01</strong>1"
"11<strong>00</strong>11" -> "11<strong>10</strong>11"
</pre>
<p><strong>示例 2</strong></p>
<pre>
<b>输入:</b>binary = "01"
<b>输出:</b>"01"
<b>解释:</b>"01" 没办法进行任何转换。
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 <= binary.length <= 10<sup>5</sup></code></li>
<li><code>binary</code> 仅包含 <code>'0'</code> 和 <code>'1'</code></li>
</ul>