微信开发中 ACCESS TOKEN 过期失效的解决方案详解
958
2022-10-02
[leetcode] 155. Min Stack
Description
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-() – Get the top element.getMin() – Retrieve the minimum element in the stack.Example:
MinStack minStack = new MinStack();minStack.push(-2);minStack.push(0);minStack.push(-3);minStack.getMin(); --> Returns -3.minStack.pop();minStack-(); --> Returns 0.minStack.getMin(); --> Returns -2.
分析
题目的意思是:实现MinStack的push,pop,top,tetrieving功能。
空间换时间最小栈只不过在原有栈的基础上增加了一个获取最小值的功能,我们可以用两个栈来模拟,第一个栈来模拟正常的栈的功能,第二个栈用来存储栈中的最小值。注意我们在pop和push的一点小小的改变。
class MinStack {private: stack
参考文献
[LeetCode] Min Stack 最小栈
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~