@@ -0,0 +1,1096 @@
+// Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.%0A%0A// For %22(()%22, the longest valid parentheses substring is %22()%22, which has length = 2.%0A%0A// Another example is %22)()())%22, where the longest valid parentheses substring is %22()()%22, which has length = 4.%0A%0Apublic class Solution %7B%0A    public int longestValidParentheses(String s) %7B%0A    %09int len = s.length();%0A%0A    %09if(len == 0) return 0;%0A%0A    %09Stack%3CInteger%3E st = new Stack%3CInteger%3E();%0A%0A    %09char%5B%5D chars = s.toCharArray();%0A    %09int accumulation = 0;%0A    %09int max = 0;%0A%0A    %09for(int i = 0; i %3C len; i++)%7B%0A    %09%09if(chars%5Bi%5D == '(')%7B%0A    %09%09%09st.push(i);%0A    %09%09%7Delse%7B%0A    %09%09%09if(st.isEmpty())%7B%0A    %09%09%09%09accumulation = 0;%0A    %09%09%09%7Delse%7B%0A    %09%09%09%09int matchedPos = st.pop();%0A    %09%09%09%09int matchedLen = i - matchedPos + 1;%0A%0A    %09%09%09%09if(st.isEmpty())%7B%0A    %09%09%09%09%09accumulation += matchedLen;%0A    %09%09%09%09%09matchedLen = accumulation;%0A    %09%09%09%09%7Delse%7B%0A    %09%09%09%09%09matchedLen = i - st.peek();%0A    %09%09%09%09%7D%0A%0A    %09%09%09%09max = max %3C matchedLen? matchedLen : max;%0A    %09%09%09%7D%0A    %09%09%7D%0A    %09%7D%0A%0A    %09return max;%0A%09%7D%0A%7D

add longest valid parentheses solution