Description
Balanced strings are those with equal number of "L" and "R" characters. Given a balanced string s, split it into the maximum number of balanced strings and return that count.
Examples
Input:
s = "RLRRLLRLRL"Output:
4Explanation:
RL, RRLL, RL, RL are balanced.
Input:
s = "LRLRLRLR"Output:
4Explanation:
LR, LR, LR, LR are all balanced. Each pair of adjacent L and R forms a balanced substring, giving us the maximum possible number of splits.
Input:
s = "LLLRRRLRRL"Output:
2Explanation:
LLLRRR, LRRL are balanced. The first 6 characters form one balanced substring (3 L's and 3 R's), and the last 4 characters form another balanced substring (2 L's and 2 R's).
Constraints
- •
2 ≤ s.length ≤ 1000