<LeetCode OJ> Min Stack【155】
2015-12-30 19:17
330 查看
155. Min Stack
My SubmissionsQuestion
Total Accepted: 55516 Total
Submissions: 263927 Difficulty: Easy
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.
push(x) -- Push element x onto stack.
pop() -- Removes the element on top of the stack.
top() -- Get the top element.
getMin() -- Retrieve the minimum element in the stack.
Subscribe to see which companies asked this question
Hide Tags
Stack Design
Hide Similar Problems
(H) Sliding Window Maximum
以下是错误答案,有待以后调试,不舍得放弃,留了下来:
//思路首先:数组模拟栈 class MinStack { public: MinStack() { arr.resize(100000); minarr.resize(100000); ntop=-1; } void push(int x) { ++ntop; arr[ntop]=x; if(ntop==0) minum=INT_MAX; if(x<=minum) minum=x; minarr[ntop]=minum; } void pop() { minarr[ntop]=0; ntop--; } int top() { return arr[ntop]; } int getMin() { return minarr[ntop]; } private: vector<int> arr; vector<int> minarr; int ntop; int minum; };
相关文章推荐
- Linux常用命令大全
- 选频方波放大电路设计
- 程序包com.sun.image.codec.jpeg不存在解决方法
- 一键安装部署代码的神器之常见问题及解决办法-----walle(瓦力)
- Git CMD - rm: Remove files from the working tree and from the index
- 排序算法之递归算法(归并排序)
- A星寻路算法之RVO动态寻路
- iOS开发中new与alloc的区别
- level改bake
- linux下redis安装
- Git CMD - mv: Move or rename a file, a directory, or a symlink
- 关于x265配置了rc.bStrictCbr =1不能进行编码的问题
- Spring @Scheduled 执行两次 问题总结
- Linux 下基于socket的简单网络聊天室
- 一键安装部署代码的神器之安装-----walle(瓦力)
- Linux常用命令大全2
- vim php代码规范
- linux下删除大量小文件方法汇总
- 数据结构:递归
- Java是如何读到hbase-site.xml 的内容的