if if else:执行完第一个if还会去判断下一个if是否满足,不满足则会执行else,即当i==’)’, stack pop弹出之后,还会去执行stack.append()
stack = []
for i in s:
if len(stack)==0:
stack.append(i)
continue
if i==')' and stack[-1]=='(':
stack.pop()
if i=='}' and stack[-1]=='{':
stack.pop()
if i==']' and stack[-1]=='[':
stack.pop()
else:
stack.append(i)
if elif else, 则在if满足之后不会去执行elif和else中的内容
stack = []
for i in s:
if len(stack)==0:
stack.append(i)
continue
if i==')' and stack[-1]=='(':
stack.pop()
elif i=='}' and stack[-1]=='{':
stack.pop()
elif i==']' and stack[-1]=='[':
stack.pop()
else:
stack.append(i)