python3----so easy
# -*- coding:utf-8 -*-
class Solution:
def __init__(self):
self.stack = []
self.minValue = []
def push(self, node):
# write code here
self.stack.append(node)
if self.minValue:
if self.minValue[-1] > node:
self.minValue.append(node)
else:
self.minValue.append(self.minValue[-1])
else:
self.minValue.append(node)
def pop(self):
# write code here
if self.stack == []:
return None
self.minValue.pop()
return self.stack.pop()
def top(self):
# write code here
if self.stack == []:
return None
return self.stack[-1]
def min(self):
# write code here
if self.minValue == []:
return None
return self.minValue[-1]
京公网安备 11010502036488号