剑指offer 编程题(19):自定义栈输出最小值
来源:互联网 发布:java打包成exe 编辑:程序博客网 时间:2024/06/05 10:03
题目描述
定义栈的数据结构,请在该类型中实现一个能够得到栈最小元素的min函数。
class Solution {public: stack<int> a; stack<int> s; void push(int value) { s.push(value); if(a.empty()) { a.push(value); } else { int min =a.top(); if(min >= value) { a.push(value); } else { a.push(min); } }} void pop() { s.pop(); a.pop(); } int top() { return s.top(); } int min() { return a.top(); }};
阅读全文
0 0
- 剑指offer 编程题(19):自定义栈输出最小值
- 剑指offer 面试题8 输出旋转数组最小值
- 剑指offer 编程题(3):链表倒序输出到vector
- 剑指offer -- 旋转数组最小值
- LintCode-剑指Offer-(12)带最小值操作的栈
- 【剑指offer】题8:旋转数组的最小值
- 剑指offer编程题
- 【剑指offer】旋转数组的最小值
- 剑指offer之旋转数组中的最小值
- [剑指offer]旋转数组的最小值
- 剑指offer(5) 旋转数组中的最小值
- 【剑指offer】旋转数组的最小值
- 【剑指offer】旋转数组的最小值
- 【剑指offer之旋转数组的最小值】
- Offer题8 旋转数组的最小值
- 剑指offer经典编程题(一)
- 剑指offer编程题(1):数组
- 剑指offer编程题01
- ztree+Ajxa 动态树形图实例展示
- nginx信号量
- 【代码全】使用SpringAOP编写日志记录(插入oracle数据库中)
- Java中ArrayList和LinkedList区别
- Android系统版本与API级别对照表
- 剑指offer 编程题(19):自定义栈输出最小值
- 【视频理解数据集汇总】A collection of recent video understanding datasets, under construction!
- MySQL数据库迁移详细步骤
- the difference between Oracle and Mysql
- UNION和UNION ALL的区别
- Allegro软件报错问题记录(持续更新中)
- 洛谷P2921 [USACO08DEC]在农场万圣节Trick or Treat on the Farm
- 多线程同步
- 业务层遍历单表查询与使用mybatis的collection实现一对多查询的效率对比