单选题 适中
#17736

以下代码用于检查字符串中的括号是否匹配,横线上应填写( )。 def is_balanced ( s ) : stack = [ ] for c in s :…

以下代码用于检查字符串中的括号是否匹配,横线上应填写( )。

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
	__________________
未登录也能判分,登录后才会记录
答案与解析
正确答案:D
这道题暂未补解析。