32. Longest Valid Parentheses
Description
Intuition
Stack Solution
The regular solution is very intuitive, using a stack.
Dp Solution
Core: The dp array store the current longest valid parentheses.
First, we need a leftCount to count the left parentheses.
- If we found a - )and- leftCount > 0, we can get a
- ()()