马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
from functools import lru_cache
@lru_cache
def removeInvalidParentheses(self, s):
if len(s) == 1 and s not in "()":
return [s]
if len(s) < 2:
return [""]
res = set()
if s[0] == "(" and s[-1] == ")":
res |= set([f"({i})" for i in removeInvalidParentheses(s[1:-1])])
for i in range(1, len(s)):
a, b = removeInvalidParentheses(s[:i]), removeInvalidParentheses(s[i:])
res |= {i+j for i in a for j in b}
print(res)
p = len(max(res, key=len))
return [i for i in res if len(i) == p]
removeInvalidParentheses(s)
代码报错如下,如何修改TypeError Traceback (most recent call last)
<ipython-input-13-806560d14b0b> in <cell line: 17>()
15 p = len(max(res, key=len))
16 return [i for i in res if len(i) == p]
---> 17 removeInvalidParentheses()
TypeError: removeInvalidParentheses() missing 2 required positional arguments: 'self' and 's'
|