Find the length of the longest valid parenthesis sequence in a string, in O(n) time
问题 My friend ran into a question in an interview and he was told that there is an O(n) solution. However, neither of us can think it up. Here is the question: There is a string which contains just ( and ) , find the length of the longest valid parentheses substring, which should be well formed. For example ")()())" , the longest valid parentheses is ()() and the length is 4. I figured it out with dynamic programming, but it is not O(n). Any ideas? public int getLongestLen(String s) { if (s ==