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) {
if(s==null||s.length()==0){
return 0;
}
Stack
stack = new Stack
(); int lastposition = -1;// the last not match position of ")" int res = 0; for(int i =0;i