这是我的测试用例->
{(<[testdata])>}-> 错误
{just{test<of>Unbalanced}String')-> 错误
{(<[ABalancedExample]>)}-> 真
opening = ['[','(','<','{']
closing = [']',')','>','}']我的代码不适用于 {(<[testdata])>} 因为没有处理括号的顺序
def check(str): count = 0 if not str: return None for i in str: if i in opening: count += 1 elif i in closing: count -= 1 if count < 0: return False return count == 0
Smart猫小萌
慕妹3146593
随时随地看视频慕课网APP
相关分类