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的更多相关文章
随机推荐
- java中的异常处理机制_finally的使用
finally总结: finally代码块:定义一定执行的代码 通常用于关闭资源或者某些一定执行的代码 实例1:finally功能演示 class FuShuException extends Exc ...
- 08_Spring实现action调用service,service调用dao的过程
[工程截图] [PersonDao.java] package com.HigginCui.dao; public interface PersonDao { public void savePers ...
- json,serialze之格式
<?php echo 'array-json:' . "\n"; $arr = array('key1'=>'value1', 'key2' => 'value2 ...
- laravel homestead
laravel homestead真是个好东西啊,折腾了很长时间,终于ok啦. 安装成功之后,在-目录下有个homstead,进入执行vagrant up clzdeMBP:Homestead clz ...
- struts2,登录功能模块实现
功能: ·UserLogin作为控制登录的Action,校验密码成功后记录session,可以选择记住登陆状态,登陆成功后自动跳转到登陆前的URL: ·UserLogout作为控制登录推出的Actio ...
- 一步步学习NHibernate(3)——NHibernate增删改查
请注明转载地址:http://www.cnblogs.com/arhat 在上一章中,我们配置了以下NHibernate的运行环境, 并介绍了NHibernate的中两个非常中重要的接口"I ...
- canvas 乒乓球
<!DOCTYPE html> <html> <head> <title>Bouncing Ball With inputs</title> ...
- Automotive Security的一些资料和心得(2):Cryptography
1. Security Goal - Confidentiality - Integrity - Availability - Authenticity - Non-repudiation - Aut ...
- @Transient注解
以下两个包都包含@Transient注解 java.beans.Transient; javax.persistence.Transient; 使用@Transient时注意区别二者
- 记录android学习、开发过程温故知新
记录android学习.开发过程温故知新