[剑指offer]包含min函数的栈
来源:互联网 发布:淘宝网商贷款额度 编辑:程序博客网 时间:2024/05/17 20:13
题目描述
定义栈的数据结构,请在该类型中实现一个能够得到栈最小元素的min函数。
class Solution {public: stack<int> s1,s2; void push(int value) { s1.push(value); if(s2.empty()) s2.push(value); else { if(s2.top()>=value) s2.push(value); else s2.push(s2.top()); } } void pop() { s1.pop(); // if(!s2.empty()) s2.pop(); } int top() { return s1.top(); } int min() { return s2.top(); }};
阅读全文
0 0
- 【剑指offer】包含min函数的栈
- 剑指offer--包含min函数的栈
- 剑指Offer-->包含min函数的栈
- 《剑指offer》包含min函数的栈
- 剑指offer - 包含min函数的栈
- 剑指offer-包含min函数的栈
- 剑指offer:包含min函数的栈
- 包含min函数的栈|剑指offer
- 剑指offer-包含min函数的栈
- 剑指offer 包含min函数的栈
- 剑指offer:包含min函数的栈
- 剑指offer 包含min函数的栈
- [剑指offer]包含min函数的栈
- 《剑指offer》-包含min函数的栈
- 剑指offer----包含min函数的栈
- 【剑指offer】包含min函数的栈
- 剑指offer|包含min函数的栈
- 《剑指offer》包含min函数的栈
- Kafka/Metaq设计思想学习笔记
- command: cat
- SSH 配置
- [HNOI2006]鬼谷子的钱袋
- mysql安装到第三步“Start Service“出现红叉,Could not start the service MySQL解决方法
- [剑指offer]包含min函数的栈
- 随手打印小纸条 小型便携萌趣纸条打印机使用评测
- 「网络流 24 题」餐巾计划
- D35 Spark源代码(待补充)
- USB在硬件设计是的注意事项
- NOIP2008~2016整合版题解
- javaIO整理
- 用delphi检查网络连接状态3种方式
- STL map相关学习整理