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
PostgreSQLv16

Siia ilmub koodi käivituse tulemus

Visible tests
1
Input
"(1+(2*3)+((8)/4))+1"
Expected3
2
Input
"(1)+((2))+(((3)))"
Expected3
3
Input
"1+1"
Expected0
4
Input
""
Expected0
5
Input
"()()"
Expected1
6
Input
"(1+(2*3)+((8)/4))+1!"
Expected3
Focus radio
Paused · SomaFM · Fluid