class Solution:
# @param s, a string
# @return an integer
def longestValidParentheses(self, s):
ret, st = 0, []
st.append((-1,')'))
for i in range(len(s)):
if s[i] == '(' or st[-1][1] == ')':
st.append((i, s[i]))
else:
st.pop()
ret = max(ret, i - st[-1][0])
return ret