We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5c0ad84 commit c0db571Copy full SHA for c0db571
scripts/algorithms/L/Longest Valid Parentheses/Longest Valid Parentheses.py
@@ -1,14 +1,15 @@
1
+# Runtime: 74 ms (Top 48.14%) | Memory: 14.8 MB (Top 24.60%)
2
class Solution:
3
def longestValidParentheses(self, s: str) -> int:
-
4
+
5
maxi = 0
6
stack = [-1]
7
8
for i in range(len(s)) :
9
if s[i] == "(" : stack.append(i)
10
else :
11
stack.pop()
12
if len(stack) == 0 : stack.append(i)
13
else : maxi = max(maxi, i - stack[-1])
14
- return maxi
15
+ return maxi
0 commit comments