检查字符串括号匹配的Python代码中横线上应填写什么内容
以下代码用于检查字符串中的括号是否匹配,横线上应填写( )。
def is_balanced(s):
stack = []
for c in s:
if c in '([{':
stack.append(c)
else:
if not stack:
return False
top = stack.pop()
if (c == ')' and top != '(') or \
(c == ']' and top != '[') or \
(c == '}' and top != '{'):
return False
__________________
正在加载题目数据…
子题
该题型需在试卷/作业中作答,单题练习暂不支持
答案解析