Longest Valid Parentheses
Hard
Strings
Stack
DP
Find the length of the longest valid parentheses substring.
Input: parentheses string
Output: length
Constraints
See problem-specific constraints. Optimized solution required.
Examples
Example 1:
Input: (()
Output:
Example 2:
Input: (()
Output:
Hints
Consider a stack approach.
Think about time complexity.
Tests:
Runtime:
Memory:
Test
Input:
Expected:
Got:
Click Run Code to test against sample cases, or Submit to test against all cases.
▲ Console