python 刷题:实现队列

牛客在线刷题,地址:
http://www.nowcoder.com/practice/54275ddae22f475981afa2244dd448c6?rp=1&ru=/ta/cracking-the-coding-interview

用两个栈来实现一个队列,完成队列的Push和Pop操作。 队列中的元素为int类型。

# -*- coding:utf-8 -*-
class Solution:
    def __init__(self):
        self.stack = []

    def push(self, node):
        # write code here
        self.stack.append(node)
    def pop(self):
        # return xx
        if self.stack != []:
            return self.stack.pop(0)
        else:
            return 0

你可能感兴趣的:(python-刷题)