leetcode之Implement Queue using Stacks

来源:互联网 发布:寿百年黑俄罗斯淘宝店 编辑:程序博客网 时间:2024/05/16 06:53

这道题就是实现栈的操作。用list来实现,很简单的。代码如下:

class Queue(object):    def __init__(self):        """        initialize your data structure here.        """        self.items = []            def push(self, x):        """        :type x: int        :rtype: nothing        """        self.items.append(x)            def pop(self):        """        :rtype: nothing        """        del self.items[0]            def peek(self):        """        :rtype: int        """        return self.items[0]            def empty(self):        """        :rtype: bool        """        if len(self.items) == 0:            return True        else:            return False


0 0