给定一个只包括 '(',')','{','}','[',']' 的字符串 s ,判断字符串是否有效。
'('
')'
'{'
'}'
'['
']'
s
dic = {'{': '}', '[': ']', '(': ')'} stack = [] for c in s: if c in dic: stack.append(c) elif not stack or dic[stack.pop()] != c: return False return not stack