题解 | #【模板】队列#

【模板】队列

https://www.nowcoder.com/practice/afe812c80ad946f4b292a26dd13ba549

class queue:
    def __init__(self) -> None:
        self.items = []

    def push(self, x: int):
        self.items.append(x)

    def pop(self):
        return self.items.pop(0) if self.items else "error"

    def front(self):
        return self.items[0] if self.items else "error"


res = queue()
for count in range(int(input())):
    action = input()
    if action[:4] == "push":
        res.push(int(action.split()[1]))
    elif action == "pop":
        print(res.pop())
    else:
        print(res.front())

全部评论

相关推荐

投递米哈游等公司10个岗位
点赞 评论 收藏
分享
ccc6660204:直接转前端,明天开始学,把自己学过Java 什么的全都忘记,不要有任何惋惜,信我,坚持到大三下你会感谢我
计算机有哪些岗位值得去?
点赞 评论 收藏
分享
码农索隆:想看offer细节
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务