代码拉取完成,页面将自动刷新
<p>You are given a binary string <code>s</code> consisting only of zeroes and ones.</p>
<p>A substring of <code>s</code> is considered balanced if<strong> all zeroes are before ones</strong> and the number of zeroes is equal to the number of ones inside the substring. Notice that the empty substring is considered a balanced substring.</p>
<p>Return <em>the length of the longest balanced substring of </em><code>s</code>.</p>
<p>A <b>substring</b> is a contiguous sequence of characters within a string.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "01000111"
<strong>Output:</strong> 6
<strong>Explanation:</strong> The longest balanced substring is "000111", which has length 6.
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> s = "00111"
<strong>Output:</strong> 4
<strong>Explanation:</strong> The longest balanced substring is "0011", which has length 4.
</pre>
<p><strong class="example">Example 3:</strong></p>
<pre>
<strong>Input:</strong> s = "111"
<strong>Output:</strong> 0
<strong>Explanation:</strong> There is no balanced substring except the empty substring, so the answer is 0.
</pre>
<p> </p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= s.length <= 50</code></li>
<li><code>'0' <= s[i] <= '1'</code></li>
</ul>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。