Leetcode 1341 Solution
This article provides solution to leetcode question 1341 (split-a-string-in-balanced-strings)
Access this page by simply typing in "lcs 1341" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/split-a-string-in-balanced-strings
Solution
class Solution:
def balancedStringSplit(self, s: str) -> int:
curr_sum = 0
ans = 0
for ch in s:
if ch == 'L':
curr_sum += 1
elif ch == 'R':
curr_sum -= 1
if curr_sum == 0:
ans += 1
return ans