题解 | #包含min函数的栈#

包含min函数的栈

http://www.nowcoder.com/practice/4c776177d2c04c2494f2555c9fcc1e49

# -*- coding:utf-8 -*-
class Solution:
    stack1=[]
    stack2=[]    
    def push(self, node):
        # write code here
        self.stack1.append(node)
        if len(self.stack2)==0:
            self.stack2.append(node)
        else:
            if node>self.min():
                self.stack2.append(self.min())
            else:
                self.stack2.append(node)
    def pop(self):
        # write code here
        self.stack1.pop()
        self.stack2.pop()        
    def top(self):
        # write code here
        return self.stack1[len(self.stack1)-1]
    def min(self):
        # write code here
        return self.stack2[len(self.stack2)-1]
全部评论

相关推荐

想问各位佬,这是挂了吗
投递小米集团等公司10个岗位
点赞 评论 收藏
分享
程序员小白条:找的太晚,别人都是大三实习,然后大四秋招春招的,你大四下了才去实习,晚1年
点赞 评论 收藏
分享
程序员小白条:太晚了,看别人找到实习了才投的话,自己本身就没啥准备,计划太晚咯,只能吞苦果子
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

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