Balanced Letter Cuts

A balanced part of a string contains the same number of L and R characters. Write a function balanced_string_split that receives a string made only of these two characters. Split it into the maximum possible number of balanced substrings. Return that count.

Примеры

Ввод
"RLRRLLRLRL"
Вывод
4
Ввод
"RLRRRLLRLL"
Вывод
2
Ввод
"LLLLRRRR"
Вывод
1

Нужно реализовать

def balanced_string_split(s: str) -> int:

Теги

stringsstack
PostgreSQLv16

Čia bus kodo vykdymo rezultatas

Visible tests
1
Input
"RLRRLLRLRL"
Expected4
2
Input
"RLRRRLLRLL"
Expected2
3
Input
"LLLLRRRR"
Expected1
4
Input
"RLRRLL"
Expected2
5
Input
"LR"
Expected1
6
Input
"RL"
Expected1
Focus radio
Paused · SomaFM · Fluid