测评会员优惠活动进行中 · 开通 VIP,有效期内测评不限次 VIP 优惠中 · 测评不限次 立即查看

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
	__________________

选项(单选)

上一题 下一题