A balanced string has the same number of 'L' and 'R' characters. Given a balanced string s, split it into substrings such that every substring is balanced. Return the maximum number of balanced strings you can obtain.
A balanced string has the same number of 'L' and 'R' characters. Given a balanced string s, split it into substrings such that every substring is balanced. Return the maximum number of balanced strings you can obtain.
Example 1:
Input: {"s":"RLRRLLRLRL"}
Output: 4
Constraints:
2≤s.length≤1000
s[i] is either 'L' or 'R'.
s is a balanced string.
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"s":"RLRRLLRLRL"}
Read 10 characters left to right. Count R as +1 and L as -1; a piece is balanced when its running total is back at 0.
R
L
R
R
L
L
R
L
R
L
balance after each character (R up, L down); every return to 0 is a cut