← 返回 meta 的题目列表Balance Parentheses
类型:online_judge
meta
Given a string consisting only of characters '(' and ')', write a function to compute the minimum number of parentheses needed to add to make the entire string balanced. A string is balanced if for every opening parenthesis there is a closing parenthesis.
Input
A string containing only characters '(' and ')'
Output
An integer representing the minimum number of parentheses needed to add
Example
Input
"(("
Output
2
Input
"())"
Output
1
Input
"()))("
Output
2
Constraints
Maximum string length is 10⁵
Example
Input
((