# 2609. Find the Longest Balanced Substring of a Binary String ###### tags: `Leetcode` `Easy` Link: https://leetcode.com/problems/find-the-substring-with-maximum-cost/ ## Code ```python= class Solution: def findTheLongestBalancedSubstring(self, s: str) -> int: zeroCnt, oneCnt, ans = 0, 0, 0 for i in range(len(s)): if s[i]=='0': if oneCnt!=0: zeroCnt, oneCnt = 0, 0 zeroCnt += 1 else: if oneCnt+1<=zeroCnt: oneCnt += 1 ans = max(ans, 2*oneCnt) return ans ```