2609. Find the Longest Balanced Substring of a Binary String Easy

@problem@discussion
#String



1/**
2 * [2609] Find the Longest Balanced Substring of a Binary String
3 *
4 * You are given a binary string s consisting only of zeroes and ones.
5 * A substring of s is considered balanced if all zeroes are before ones 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.
6 * Return the length of the longest balanced substring of s.
7 * A substring is a contiguous sequence of characters within a string.
8 *  
9 * <strong class="example">Example 1:
10 * 
11 * Input: s = "01000111"
12 * Output: 6
13 * Explanation: The longest balanced substring is "000111", which has length 6.
14 * 
15 * <strong class="example">Example 2:
16 * 
17 * Input: s = "00111"
18 * Output: 4
19 * Explanation: The longest balanced substring is "0011", which has length 4. 
20 * 
21 * <strong class="example">Example 3:
22 * 
23 * Input: s = "111"
24 * Output: 0
25 * Explanation: There is no balanced substring except the empty substring, so the answer is 0.
26 * 
27 *  
28 * Constraints:
29 * 
30 * 	1 <= s.length <= 50
31 * 	'0' <= s[i] <= '1'
32 * 
33 */
34pub struct Solution {}
35
36// problem: https://leetcode.com/problems/find-the-longest-balanced-substring-of-a-binary-string/
37// discuss: https://leetcode.com/problems/find-the-longest-balanced-substring-of-a-binary-string/discuss/?currentPage=1&orderBy=most_votes&query=
38
39// submission codes start here
40
41impl Solution {
42    pub fn find_the_longest_balanced_substring(s: String) -> i32 {
43        0
44    }
45}
46
47// submission codes end
48
49#[cfg(test)]
50mod tests {
51    use super::*;
52
53    #[test]
54    fn test_2609() {
55    }
56}
57


Back
© 2025 bowen.ge All Rights Reserved.