Deepest Parentheses
In expressions, parentheses can be nested inside each other, and sometimes you need to know the deepest nesting level. Given a string s with balanced parentheses, return the maximum nesting depth. If there are no parentheses, return 0.
Примеры
Ввод
"(1+(2*3)+((8)/4))+1"Вывод
3Ввод
"(1)+((2))+(((3)))"Вывод
3Ввод
"1+1"Вывод
0Нужно реализовать
def max_depth(s: str) -> int:
Теги
stringsstack
Prihláste sa, aby ste videli históriu odoslaní
Prihlásiť saPrihláste sa, aby ste mohli používať AI mentora
Prihlásiť saVisible tests
1
Input
"(1+(2*3)+((8)/4))+1"Expected
32
Input
"(1)+((2))+(((3)))"Expected
33
Input
"1+1"Expected
04
Input
""Expected
05
Input
"()()"Expected
16
Input
"(1+(2*3)+((8)/4))+1!"Expected
3Focus radio
Paused · SomaFM · Fluid