2023-12-09 18:42:21 +08:00
< p > Given a string containing just the characters < code > ' (' < / code > and < code > ' )' < / code > , return < em > the length of the longest valid (well-formed) parentheses < / em > < span data-keyword = "substring-nonempty" > < em > substring< / em > < / span > .< / p >
2022-03-27 18:35:17 +08:00
< p > < / p >
2023-12-09 18:42:21 +08:00
< p > < strong class = "example" > Example 1:< / strong > < / p >
2022-03-27 18:35:17 +08:00
< pre >
< strong > Input:< / strong > s = " (()"
< strong > Output:< / strong > 2
< strong > Explanation:< / strong > The longest valid parentheses substring is " ()" .
< / pre >
2023-12-09 18:42:21 +08:00
< p > < strong class = "example" > Example 2:< / strong > < / p >
2022-03-27 18:35:17 +08:00
< pre >
< strong > Input:< / strong > s = " )()())"
< strong > Output:< / strong > 4
< strong > Explanation:< / strong > The longest valid parentheses substring is " ()()" .
< / pre >
2023-12-09 18:42:21 +08:00
< p > < strong class = "example" > Example 3:< / strong > < / p >
2022-03-27 18:35:17 +08:00
< pre >
< strong > Input:< / strong > s = " "
< strong > Output:< / strong > 0
< / pre >
< p > < / p >
< p > < strong > Constraints:< / strong > < / p >
< ul >
< li > < code > 0 < = s.length < = 3 * 10< sup > 4< / sup > < / code > < / li >
< li > < code > s[i]< / code > is < code > ' (' < / code > , or < code > ' )' < / code > .< / li >
< / ul >