Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def longestValidParentheses(self, s):
- """
- :type s: str
- :rtype: int
- """
- maxans = 0
- st = []
- st.append(-1)
- for i in range(0, len(s)):
- if s[i] == '(':
- st.append(i)
- else:
- st.pop()
- if not st:
- st.append(i)
- else:
- maxans = max(maxans, i - st[-1])
- return maxans
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement