32. Longest Valid Parentheses

Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.
For "(()", the longest valid parentheses substring is "()", which has length = 2.
Another example is ")()())", where the longest valid parentheses substring is "()()", which has length = 4.

public class Solution {
    public int longestValidParentheses(String s) {
        int maxLen = 0;
        Stack stack = new Stack();
        int left = 0;
        for(int i=0;i

你可能感兴趣的:(32. Longest Valid Parentheses)