1221. Split a String in Balanced Strings

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1221

class Solution:
    def balancedStringSplit(self, s: str) -> int:
        res = l = 0
        for c in s:
            if c == 'L':
                l += 1
            else:
                l -= 1
            if l == 0:
                res += 1
        return res