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.

  1. If we found a ) and leftCount > 0, we can get a

  2. ()()

Pitfall

Solution

results matching ""

    No results matching ""