MCPcopy Create free account
hub / github.com/codedecks-in/LeetCode-Solutions / Solution

Class Solution

Python/longest-valid-parentheses.py:7–20  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5Space complexity: O(n)
6'''
7class Solution(object):
8 def longestValidParentheses(self, s):
9 ans=0
10 stack=[-1]
11 for i in range(len(s)):
12 if(s[i]=='('):
13 stack.append(i)
14 else:
15 stack.pop()
16 if(len(stack)==0):
17 stack.append(i)
18 else:
19 ans=max(ans,i-stack[-1])
20 return ans

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected