class Solution:

    def balancedStringSplit(self, s: str) ->int:
        balance = ans = 0
        for ch in s:
            if ch == 'L':
                balance -= 1
            else:
                balance += 1
            if balance == 0:
                ans += 1
        return ans

2e2e4f98bc5efc53d51cdcb4e278d45d81cda6a5
<mask token>

class Solution:
    <mask token>

class Solution:

    def balancedStringSplit(self, s: str) ->int:
        balance = ans = 0
        for ch in s:
            if ch == 'L':
                balance -= 1
            else:
                balance += 1
            if balance == 0:
                ans += 1
        return ans
