class Solution(object):
def longestValidParentheses(self, s):
"""
:type s: str
:rtype: int
"""
maxlen=0
stack=[]
last=-1
for i in range(len(s)):
if s[i] == '(':
stack.append(i)
else:
if stack == []:
last=i
else:
stack.pop()
if stack == []:
maxlen=max(maxlen,i-last)
else:
maxlen=max(maxlen,i-stack[len(stack)-1])
return maxlen
相关文章
- 03-08[LeetCode][Python]Longest Palindromic Substring
- 03-08Leecode32 longest-valid-parentheses
- 03-08leetcode Longest Valid Parentheses python
- 03-08LeetCode20 Valid Parentheses
- 03-08LeetCode(49)-Valid Parentheses
- 03-08[LeetCode] 20. Valid Parentheses_Easy tag: Stack
- 03-08【Python】32. Longest Valid Parentheses
- 03-08【leetcode】Longest Valid Parentheses
- 03-08【LeetCode练习题】Longest Valid Parentheses
- 03-08【一天一道LeetCode】#32. Longest Valid Parentheses