题解 | #有效括号序列#
有效括号序列
http://www.nowcoder.com/practice/37548e94a270412c8b9fb85643c8ccc2
class Solution:
def isValid(self , s: str) -> bool:
if not s: return False
if len(s)%2!=0: return False
match,mark={')':'(',']':'[','}':'{'},[]
for item in s:
if item in ['(','[','{']:
mark.append(item)
elif item in [')',']','}']:
if not mark: return False
if mark[-1]==match[item]:
mark.pop()
else: return False
return not mark
题解-数据结构与算法 文章被收录于专栏
小菜鸟的题解