题解 | #包含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]
全部评论

相关推荐

Cl_Wg:看牛客匿名贴容易抑郁,白菜就是我的天花板
点赞 评论 收藏
分享
哞客37422655...:嫡系回归,buff叠满!好好干,等你们组明年把你当嫡长继承人的时候再请我们喝奶茶~
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

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