1221. Split a String in Balanced Strings

Обновлено: 2024-03-12
1 мин
[]

Содержание

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