32.Longest-Valid-Parentheses
32. Longest Valid Parentheses
题目地址
题目描述
Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.
Example 1:
Input: "(()"
Output: 2
Explanation: The longest valid parentheses substring is "()"
Example 2:
Input: ")()())"
Output: 4
Explanation: The longest valid parentheses substring is "()()"代码
Approach 1: Dynamic Programming
Approach #2 Dyanmic Programming
Approach #2 Using Stack
Approach #3 Without extra space
Last updated