32. Longest Valid Parentheses
Hard
10.7K
338

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
604.9K
Submissions
1.8M
Acceptance Rate
32.8%

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

Discussion (0)

Related Topics
Copyright ©️ 2023 LeetCode All rights reserved