题解 | #点击消除#
点击消除
https://www.nowcoder.com/practice/8d3643ec29654cf8908b5cf3a0479fd5
import sys stack = [] for line in sys.stdin: line = line.strip() # 去除行末尾的换行符,否则换行符也算作一个字符导致栈不为空 for s in line: if stack and stack[-1] == s: stack.pop() else: stack.append(s) if not stack: print(0) else: for c in stack: print(c, end="")