20.有效的括号(通过)
程序员文章站
2022-07-12 11:58:45
...
class Solution:
def isValid(self, s):
"""
:type s: str
:rtype: bool
"""
vl = {'{':1,'}':-1,'[':2,']':-2,'(':3,')':-3}
y = list(s)
llong = len(y)
result = []
for i in range(llong):
if vl[y[i]] > 0:
result.append(vl[y[i]])
else:
if len(result) == 0:
return False
elif (result[len(result)-1] + vl[y[i]]) != 0:
return False
else:
result.pop()
if len(result) == 0:
return True
else:
return False
上一篇: LintCode1661. 删除链表中的第n到m个节点
下一篇: Leecode刷题1——两数之和