
Longest Valid Parentheses (hard)
Problem Statement
You are given a string containing just the characters '(' and ')'. Your task is to find the length of the longest valid (well-formed) parentheses substring.
Example 1:
- Input:
"(())" - Expected Output:
4 - Justification: The entire string is a valid parentheses substring.
Example 2:
- Input:
")()())" - Expected Output:
4 - Justification: The longest valid parentheses substring is
"()()".
Example 3:
- Input:
"(()" - Expected Output:
2 - Justification: The longest valid parentheses substring is
"()".
Constraints:
- 0 <= s.length <= 3 * 10<sup>4</sup>
s[i]is '(', or ')'.
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Unlock this and all other premium problems.
No code editor for this lesson
This lesson focuses on concepts and theory