java.lang.Object
g2601_2700.s2609_find_the_longest_balanced_substring_of_a_binary_string.Solution

public class Solution extends Object
2609 - Find the Longest Balanced Substring of a Binary String.<p>Easy</p> <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 <strong>substring</strong> is a contiguous sequence of characters within a string.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;01000111&rdquo;</p> <p><strong>Output:</strong> 6</p> <p><strong>Explanation:</strong> The longest balanced substring is &ldquo;000111&rdquo;, which has length 6.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;00111&rdquo;</p> <p><strong>Output:</strong> 4</p> <p><strong>Explanation:</strong> The longest balanced substring is &ldquo;0011&rdquo;, which has length 4.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> s = &ldquo;111&rdquo;</p> <p><strong>Output:</strong> 0</p> <p><strong>Explanation:</strong> There is no balanced substring except the empty substring, so the answer is 0.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= s.length <= 50</code></li> <li><code>'0' <= s[i] <= '1'</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • findTheLongestBalancedSubstring

      public int findTheLongestBalancedSubstring(String s)