当前位置:网站首页>剑指Offer(二十):包含min函数的栈
剑指Offer(二十):包含min函数的栈
2022-07-26 10:36:00 【康斯坦奇】
解法1:对于python来讲,栈就是用list实现的!
class Solution:
def __init__(self):
self.stack = []
self.assist = []
def push(self,node):
min = self.min()
if not min or node < min:
self.assist.append(node)
else:
self.assist.append(min)
self.stack.append(node)
def pop(self):
if self.stack:
self.assist.pop()
return self.stack.pop()
def top(self):
if self.stack:
return self.stack[-1]
def min(self):
if self.assist:
return self.assist[-1]
边栏推荐
- Redis implementation of distributed lock solution
- .net operation redis sorted set ordered set
- [leetcode每日一题2021/2/13]448. 找到所有数组中消失的数字
- The problem of large fluctuation of hx711 data
- Issue 5: the second essential skill for College Students
- 并行、并发及对于高并发优化的几个方向
- Issue 7: how do you choose between curling up and lying flat
- [leetcode每日一题2021/4/29]403. 青蛙过河
- Oracle cannot start tnslistener service cannot start
- Tradingview 使用教程
猜你喜欢
[leetcode每日一题2021/8/31]1109. 航班预订统计【中等】差分数组
英语基础句型结构------起源
数据分析入门 | kaggle泰坦尼克任务(一)—>数据加载和初步观察
Tradingview 使用教程
2022/07/25 ------ arrangement of strings
Okaleido ecological core equity Oka, all in fusion mining mode
数据分析入门 | kaggle泰坦尼克任务
QRcode二维码(C语言)遇到的问题
反射机制简述
Analysis of the transaction problem of chained method call
随机推荐
粽子大战 —— 猜猜谁能赢
.net operation redis list list
Simple use of json-c Library -- converting JSON files to struct
GIS方法类期刊和论文的综述(Introduction)怎么写?
Analyze the hybrid construction objects in JS in detail (construction plus attributes, prototype plus methods)
超图 影像 如何去除黑边(两种方法)
[leetcode每日一题2021/2/13]448. 找到所有数组中消失的数字
Zongzi battle - guess who can win
Mlx90640 infrared thermal imager temperature sensor module development notes (VI) pseudo color coding of infrared images
C语言计算日期间隔天数
工厂模式详解
12 复制对象时勿忘其每一个成分
What if MySQL can't get in
Introduction to data analysis | kaggle Titanic mission
The problem of large fluctuation of hx711 data
js下载文件,FileSaver.js导出txt、excel文件
MD5 encryption
分布式锁解决方案之Redis实现
Uniapp uses the simple method signalr (only for web debugging, cannot package apps)
移动端双指缩放事件(原生),e.originalEvent.touches