题解 | #点击消除#

点击消除

https://www.nowcoder.com/practice/8d3643ec29654cf8908b5cf3a0479fd5

def optimize_delete(s):
    stack = []
    for char in s:
        if not stack or stack[-1] != char:
            stack.append(char)
        else:
            stack.pop()
    return '0' if not stack else ''.join(stack)

s = input()
print(optimize_delete(s))

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务