题解 | #点击消除#
点击消除
https://www.nowcoder.com/practice/8d3643ec29654cf8908b5cf3a0479fd5
string = input() stack = [] for s in string: if stack.__len__()==0: stack.append(s) elif s==stack[-1]: stack.pop() else: stack.append(s) if stack.__len__()==0: print(0) else: print(''.join(stack))
抄的前面一位大佬的,采用栈的思路,优化了一下代码,让代码更优雅。