How would you design a stack which, in addition to push and pop, also has a function
min which returns the minimum element? Push, pop and min should all operate in
O(1) time.
public class StackWithMin extends Stack<NodeWithMin> {
public void push(int value) {
int newMin = Math.min(value, min());
super.push(new NodeWithMin(value, newMin));
}
}
public int min() {
if (this.isEmpty()) {
return Integer.MAX_VALUE;
} else {
return peek().min;
}
}
class NodeWithMin {
public int value;
public int min;
public NodeWithMin(int v, int min){
value = v;
this.min = min;
}
}
分享到:
相关推荐
Pro MERN Stack Full Stack Web App Development with Mongo Express React and Node.pdf Pro MERN Stack Full Stack Web App Development with Mongo Express React and Node.pdf Pro MERN Stack Full Stack Web ...
栈, 最小值
Hands-On Full-Stack Development with Swift 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书
Develop rich and scalable applications with the new MEAN Stack Key Features Learn how to construct modern web applications with Node.js, Express.js, MondoDB, and Aurelia. Harness the power of the ...
Hands-On Full-Stack Development with Swift_Code 源码 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书
本源码实现了两个类,一个是带有最大值的栈和一个是带有最大值的队列。栈利用了两个C++的stack,队列利用了C++的queue。
Using Vapor, we will build a full-stack web application that will act as an API server for our iOS and tvOS app, and will also be our web server, which will render a web view of our app. Several ...
Hands-On Full Stack Development with Go - Mina Andrawos(2019),Go全栈开发,epub格式,欢迎下载
Supported by Puppet and available with various plugins, Elastic Stack is the best option for your server log management. You will learn how to use and configure Elastic Stack independently and ...
C语言头文件 STACKC语言头文件 STACKC语言头文件 STACKC语言头文件 STACKC语言头文件 STACKC语言头文件 STACKC语言头文件 STACKC语言头文件 STACKC语言头文件 STACKC语言头文件 STACKC语言头文件 STACKC语言头文件 ...
If you are a web or full-stack JavaScript developer JavaScript developer and has tried hands on the traditional stacks, such as LAMP, MEAN, or MERN, and wish to explore a new stack with modern web ...
Full Stack Web Development with Raspberry Pi 3 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
gridstack.js是一款响应式可拖拽的元素组件网格布局jQuery插件。该jQuery插件允许你创建给予Bootstarp v3的响应式可拖拽的网格布局界面,可以用于制作可拖拽的多列网格布局。并且它还可以支持触摸屏设备。
Building Hybrid Clouds with Azure Stack 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
Full Stack JavaScript Development With MEAN 英文azw3 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
Write Modern Web Apps with the MEAN Stack Mongo Express AngularJS and Node.js 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
JEDEC JEP158:2009 3D Chip Stack with Through-Silicon Vias (TSVS):Identifying, Evaluating and Understanding Reliability Interactions - 完整英文电子版(21页).zip
With Pro MEAN Stack Development you will quickly learn everything needed to work effectively with MEAN, from setting up your toolstack to rolling out your free servers, and deploying on any device....
无线移动的Z-Stack操作系统简单介绍和图解。
Create a RESTful web service with Spring Boot Use React for frontend programming Learn to create unit tests using JUnit Discover techniques to secure the backend using Spring Security Employ Material-...