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)/最长平衡子字符串 [find-the-longest-balanced-substring-of-a-binary-string].html
2023-04-04 00:26:09 +08:00

43 lines
1.6 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>1</code> 组成的二进制字符串 <code>s</code><span style="">&nbsp;</span><span style="">&nbsp;</span></p>
<p>如果子字符串中 <strong>所有的<span style=""> </span></strong><code><span style="">0</span></code><strong><span style=""> </span>都在 </strong><code>1</code><strong> 之前</strong> 且其中 <code>0</code> 的数量等于 <code>1</code> 的数量,则认为 <code>s</code> 的这个子字符串是平衡子字符串。请注意,空子字符串也视作平衡子字符串。<span style="">&nbsp;</span></p>
<p>返回&nbsp;<span style=""> </span><code>s</code> 中最长的平衡子字符串长度。</p>
<p>子字符串是字符串中的一个连续字符序列。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>s = "01000111"
<strong>输出:</strong>6
<strong>解释:</strong>最长的平衡子字符串是 "000111" ,长度为 6 。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>s = "00111"
<strong>输出:</strong>4
<strong>解释:</strong>最长的平衡子字符串是 "0011" ,长度为 <span style="">&nbsp;</span>4 。
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>s = "111"
<strong>输出:</strong>0
<strong>解释:</strong>除了空子字符串之外不存在其他平衡子字符串,所以答案为 0 。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 50</code></li>
<li><code>'0' &lt;= s[i] &lt;= '1'</code></li>
</ul>