代码: def isValid( s): dic = {'(': ')', '{': '}', '[': ']', '?': '?'} stack = ['?'] for x in s: if x in dic: stack.append(x) elif dic[stack.pop()] != x: return False return len(stack) == 1 s='{}{()' print(isValid(s))