2609
2609
给你一个仅由 0 和 1 组成的二进制字符串 s 。 如果子字符串中 所有的 0 都在 1 之前 且其中 0 的数量等于 1 的数量,则认为 s 的这个子字符串是平衡子字符串。请注意,空子字符串也视作平衡子字符串。 返回 s 中最长的平衡子字符串长度。 子字符串是字符串中的一个连续字符序列。 示例 ......
2609. 最长平衡子字符串
给你一个仅由 0 和 1 组成的二进制字符串 s 。 如果子字符串中 所有的 0 都在 1 之前 且其中 0 的数量等于 1 的数量,则认为 s 的这个子字符串是平衡子字符串。请注意,空子字符串也视作平衡子字符串。 返回 s 中最长的平衡子字符串长度。 子字符串是字符串中的一个连续字符序列。 示例 ......
[LeetCode] 2609. Find the Longest Balanced Substring of a Binary String
You are given a binary string s consisting only of zeroes and ones. A substring of s is considered balanced if all zeroes are before ones and the numb ......
2609. 最长平衡子字符串
题目链接:2609. 最长平衡子字符串 方法:模拟 解题思路 统计当前$0$和$1$的数量$cnt0$,$cnt1$,如果当前字符为'$0$',且$1$的数量不为$0$,说明$0$前面出现$1$,则重置$cnt0 = 1$,$cnt1 = 0$。每次计算当前的最大值。 代码 class Soluti ......