32. Longest Valid Parentheses
Hard
11K
352

Given a string containing just the characters '(' and ')', return the length of the longest valid (well-formed) parentheses

.

 

Example 1:

Input: s = "(()"
Output: 2
Explanation: The longest valid parentheses substring is "()".

Example 2:

Input: s = ")()())"
Output: 4
Explanation: The longest valid parentheses substring is "()()".

Example 3:

Input: s = ""
Output: 0

 

Constraints:

  • 0 <= s.length <= 3 * 104
  • s[i] is '(', or ')'.
Accepted
619.7K
Submissions
1.9M
Acceptance Rate
32.9%

Seen this question in a real interview before?
1/4
Yes
No

Discussion (0)

Related Topics
Copyright ©️ 2023 LeetCode All rights reserved