Problem
Given a string s of only ( and ), return the length of the longest contiguous substring that is a well-formed (balanced and properly nested) set of parentheses.
Example 1
- Input
- s = "(()"
- Output
- 2
- Why
- "()"
Example 2
- Input
- s = ")()())"
- Output
- 4
- Why
- "()()"
Example 3
- Input
- s = ""
- Output
- 0
Constraints
0 <= s.length <= 3 * 10^4Each s[i] is ( or ).