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的更多相关文章

随机推荐

  1. dapper关联关系查询小测试

    测试实体类(表结构) public class User { public int user_id { get; set; } public string user_name { get; set; ...

  2. 7zip self-extracted executable: To extract file to specific directory

    1) Install 7-zip (7zS.sfx will be installed to C:\Program Files\7-Zip): http://7zsfx.solta.ru/en/ 2) ...

  3. HTML5之字体

    - 使用CSS样式来定义 context.font = [CSS font property] context.font = [font-style font-variant font-weight ...

  4. MySQL 数据库增量数据恢复案例

    MySQL 数据库增量数据恢复案例 一.场景概述 MySQL数据库每日零点自动全备 某天上午10点,小明莫名其妙地drop了一个数据库 我们需要通过全备的数据文件,以及增量的binlog文件进行数据恢 ...

  5. ehcache集群的配置

    一:配置环境 本文是在测试demo的基础上写的,服务器包括申请的两台服务器和本机,共三台服务器.demo的目标是实现三台服务器之间共享cache. 申请的两台服务器地址分别是172.19.100.15 ...

  6. lnmp 虚拟主机配置及重写

    lnmp安装与调试,请看 http://www.cnblogs.com/lin3615/p/4376224.html 虚拟主机的配置编辑nginx配置文件 nginx.conf此为主配置文件 vim ...

  7. jsoup 对网页中图片解析

    Elements article = new Elements(); Elements Img = new Elements(); article = doc.select("div#con ...

  8. CRUD生成器DBuilder设计与实现

    源码位于github:https://github.com/lvyahui8/dbuilder.git .文中图片如果太小看不清楚,请右键点击“在新标签页中打开”即可看到原图 有兴趣还可以加QQ群交流 ...

  9. struct--file_operations

    struct--file_operations-----------------------------------------    struct file_operations是一个字符设备把驱动 ...

  10. Authentication for the REST APIs

    HTTP基本认证原理 在HTTP协议进行通信的过程中,HTTP协议定义了基本认证过程以允许HTTP服务器对WEB浏览器进行用户身份认证的方法,当一个客户端向HTTP服务器进行数据请求时,如果客户端未被 ...