Skip to content

Commit a5b6351

Browse files
authored
Added Solution.py
1 parent a1a7740 commit a5b6351

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution:
2+
def longestValidParentheses(self, s):
3+
"""
4+
:type s: string
5+
:rtype int
6+
"""
7+
8+
Longest = temp = 0
9+
stack = []
10+
11+
for i in s:
12+
if i == '(' :
13+
stack.append(i)
14+
elif len(stack) != 0 and stack[-1] == '(' :
15+
stack.pop()
16+
temp += 2
17+
else:
18+
stack=[]
19+
if temp > Longest:
20+
Longest = temp
21+
temp = 0
22+
if temp > Longest:
23+
Longest = temp
24+
return Longest

0 commit comments

Comments
 (0)