Description
Given a string of parentheses, return the minimum number of parentheses you must add to make it valid.
Examples
Input:
s = "())"Output:
1Explanation:
Add one '(' at start.
Input:
s = "((("Output:
3Explanation:
Need to add 3 closing parentheses ')' to match the 3 opening parentheses '('
Input:
s = ")()(("Output:
3Explanation:
Need to add 1 opening parenthesis '(' at the beginning to match the first ')' and 2 closing parentheses '))' to match the last two '((' characters
Constraints
- •
1 ≤ s.length ≤ 1000