PowerStack
int curInc;
HashMap<Integer, Integer> incMap;
Stack<Integer> stack; public SuperStack() {
this.curInc = 0;
this.incMap = new HashMap<Integer, Integer>();
this.stack = new Stack<Integer>();
} private void push(int val) {
this.stack.push(val);
} private int pop() {
if (incMap.containsKey(stack.size())) {
curInc += incMap.get(stack.size());
}
int ret = stack.pop() + curInc;
return ret;
} private void inc(int index, int inc) {
if (incMap.containsKey(index)) {
incMap.put(index, incMap.get(index) + inc);
} else {
incMap.put(index, inc);
}
}
Normal Solution
private void push(int val) {
list.addLast(val);
}
private int pop() {
return list.pollLast();
}
private void inc(int a, int b) {
for (int i = 0; i < a; i++) {
list.set(i, list.get(i) + b);
}
}
PowerStack的更多相关文章
随机推荐
- VS2010 VS2012 如何连接Oracle 11g数据库
oracle是开发者常用的数据库,在做.NET开发是,由于Vs自带的驱动只能连接oracle 10g及以下版本,那么如何连接oracle 11g呢? 工具/原料 事先安装VS2010或者VS201 ...
- Linq JsRender
http://blog.csdn.net/linfei721/article/details/8973683
- 【html】【20】高级篇--轮播图[聚焦]
下载: http://sc.chinaz.com/jiaoben/151204445580.htm 效果: html <!doctype html> <html> <he ...
- Java线程间通信--生产者消费者
class ProducerConsumerDemo { public static void main(String[] args) { Resource r = new ...
- 虚拟机单一网卡设置两个IP
一.在虚拟机里修改虚拟网卡配置 cd /ect/sysconfig/network-scripts/ vi ifcfg-eth0 改BOOTPROTO=static cp ifcfg-eth0 ifc ...
- 暑假集训(2)第六弹 ----- Frosh Week(UVA11858)
H - Frosh Week Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:32768KB ...
- JavaScript中的apply和call函数详解
本文是翻译Function.apply and Function.call in JavaScript,希望对大家有所帮助 转自“http://www.jb51.net/article/52416.h ...
- jsonp使用规范
这两天花了很多时间弄研究jsonp这个东西, 可是无论我怎么弄..TMD就是不进入success函数,并且一直进入error函数...让我着实DT啊. 可以看下我之间的提问(这就是我遇到的烦恼).. ...
- jquery 循环显示div的示例代码
我们用一个语句就让下面五个div显示成功,具体实现如下,感兴趣的朋友可以参考下 直接看例子 复制代码代码如下: for(var p=1; p<=5; p++){ $("#proper ...
- 开发设计模式(九)门面模式(Facade Pattern)
什么是门面模式? 门面模式要求一个子系统的外部与其内部的通信必须通过一个统一的门面(Facade)对象进行.门面模式提供一个高层次的接口,使得子系统更易于使用. 大家都写过纸质的信件吧,比如给女朋友写 ...