Description
Given a string containing just the characters '(' and ')', return the length of the longest valid (well-formed) parentheses substring.
Examples
Input:
s = "(()"Output:
2Explanation:
The longest valid parentheses substring is "()".
Input:
s = ")()())"Output:
4Explanation:
The longest valid parentheses substring is "()()".
Input:
s = ""Output:
0Explanation:
Empty string has no valid parentheses.
Constraints
- •
0 ≤ s.length ≤ 3 × 10⁴ - •
s[i] is '(' or ')'.