A28565. 以下代码用于检查字符串中的括号是否匹配,横线上应填写( )。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 == ']' …
单选题
困难
知识点
题目描述
以下代码用于检查字符串中的括号是否匹配,横线上应填写( )。
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
__________________选项(单选)
答案解析
详细答案解析为会员权益,按每日次数查看。
开通 / 升级会员
上一题
下一题