Problems

30. Longest Valid Parentheses

HardStackAmazonGoogle

Given a string containing only parentheses, return the length of the longest valid parentheses substring.

Example 1:

Input: s = "(()"
Output: 2

Example 2:

Input: s = ")()())"
Output: 4

Constraints:

  • 0 <= s.length <= 3 * 10^4
Core code mode
● Auto-savedLine 1, column 1