1221. Split a String in Balanced Strings
On This Page
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