Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions solution/032.Longest Valid Parentheses/Solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Solution:
def longestValidParentheses(self, s):
"""
:type s: string
:rtype int
"""

Longest = temp = 0
stack = []

for i in s:
if i == '(' :
stack.append(i)
elif len(stack) != 0 and stack[-1] == '(' :
stack.pop()
temp += 2
else:
stack=[]
if temp > Longest:
Longest = temp
temp = 0
if temp > Longest:
Longest = temp
return Longest