Fix the Parentheses

A parentheses string is valid when every opening ( has a matching closing ) in the correct order. Given a string s containing only parentheses, find the minimum number of parentheses you need to add to make it valid. Return that minimum number.

Примеры

Ввод
"())"
Вывод
1
Ввод
"((("
Вывод
3
Ввод
"()"
Вывод
0

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

def min_add_to_make_valid(s: str) -> int:

Теги

stringsstack
PostgreSQLv16

Šeit parādīsies koda izpildes rezultāts

Visible tests
1
Input
"())"
Expected1
2
Input
"((("
Expected3
3
Input
"()"
Expected0
4
Input
"()))(("
Expected4
5
Input
""
Expected0
6
Input
")("
Expected2
Focus radio
Paused · SomaFM · Fluid