[刷题]Implement Queue by Two Stacks
2015-09-03 17:36
441 查看
[LintCode]Implement Queue by Two Stacks
public class Solution { private Stack<Integer> stack1; private Stack<Integer> stack2; public Solution() { // 2015-09-03 stack1 = new Stack<>(); stack2 = new Stack<>(); } public void push(int element) { stack1.push(element); } public int pop() { if (stack2.isEmpty()) { while (!stack1.isEmpty()) { stack2.push(stack1.pop()); } } return stack2.pop(); } public int top() { if (stack2.isEmpty()) { while (!stack1.isEmpty()) { stack2.push(stack1.pop()); } } return stack2.peek(); } }
相关文章推荐
- 九度OJ 题目1119:Integer Inquiry
- 让UITextView文字垂直居中
- UITextFiledView页面之间的相互传值
- Android UI设计(引导界面):ViewPager之三PagerTabStrip与PagerTitleStrip添加标题栏的区别
- jquey.fullpage详解
- UINavigaionController中的传值(协议)
- Android UI设计——ViewPage的无限循环(五)
- Arduino LM35温度检测
- RYU的GUI安装
- 黑马程序员—————Java基础--------GUI
- Android UI设计——ViewPage中自定义标题栏(四)
- UI触屏的操作初识
- 使用eventqueue.invokelater()好处、原因
- UIAlertView
- ios开发 UI阶段第八周
- UINavigationController
- 区间离散化+线段树区间求最值poj 3368 Frequent values
- Drupal安装百度编辑器Ueditor for wysiwyg
- iOS软件开发之在UIScrollView上添加手势不能触发解决办法
- this class is not key value coding-compliant for the key progressVIew