Untitled
unknown
plain_text
a year ago
428 B
13
Indexable
import functools
class Solution:
def longestValidParentheses(self, s: str) -> int:
@functools.lru_cache(maxsize=None)
def dfs(i, l, r):
if i == len(s):
return 2 * min(l, r)
if s[i] == "(":
l += 1
else:
r += 1
if r > l:
l = r = 0
return dfs(i + 1, l, r)
return dfs(0, 0, 0)Editor is loading...
Leave a Comment