Skip to content

225 implement stack using queues

225. Implement Stack using Queues

题目:

https://leetcode.com/problems/implement-stack-using-queues/

难度:

Easy

又到了作弊神预言Python的强项

class Stack(object):
    def __init__(self):
        """
        initialize your data structure here.
        """
        self.lst = []


    def push(self, x):
        """
        :type x: int
        :rtype: nothing
        """
        self.lst.append(x)


    def pop(self):
        """
        :rtype: nothing
        """
        self.lst.remove(self.lst[-1])


    def top(self):
        """
        :rtype: int
        """
        return self.lst[-1]

    def empty(self):
        """
        :rtype: bool
        """
        return self.lst == []



回到顶部