剑指offer:栈的压力、弹出序列
来源:互联网 发布:matlab读取字符串数组 编辑:程序博客网 时间:2024/05/29 10:58
剑指offer:面试题22
判断栈的压力和弹出顺序
import java.util.Scanner;import java.util.Stack;public class IsPopOrder {/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stubScanner scan = new Scanner(System.in);String pushorder = scan.nextLine();String poporder = scan.nextLine();IsPopOrder ipo = new IsPopOrder();boolean result = ipo.ispoporder(pushorder, poporder);System.out.println(result);}public boolean ispoporder(String pushorder, String poporder) {if (pushorder.length() != poporder.length())return false;if (pushorder == null || pushorder.length() == 0)return false;boolean result = false;Stack<Character> stack = new Stack<Character>();int n = 0;int i = 0;while (i != poporder.length()) {if (stack.size() == 0||stack.peek() != poporder.charAt(i)) {if(n==poporder.length()){break;}stack.push(pushorder.charAt(n));n++;} else {stack.pop();i++;}}if (stack.size() != 0) {result = false;} else {result = true;}return result;}}
0 0
- 剑指offer:栈的压力、弹出序列
- 剑指offer — 栈的弹出序列
- 【剑指offer】栈的压入弹出序列
- 剑指offer系列源码-栈的压入、弹出序列
- 剑指offer--栈的压入、弹出序列
- 剑指Offer之 - 栈的压入、弹出序列
- 剑指offer:栈的压入、弹出序列
- 《剑指offer》栈的压入、弹出序列
- 剑指Offer系列---(24)栈的压入、弹出序列
- 栈的压入、弹出序列(剑指offer)
- 剑指 offer:栈的压入、弹出序列
- 【剑指Offer】栈的压入、弹出序列
- 剑指offer—栈的压入、弹出序列
- 剑指offer:栈的压入弹出序列
- 剑指Offer-22-栈的压入、弹出序列
- 《剑指offer》——栈的压入、弹出序列
- 剑指offer:栈的压入、弹出序列
- 【剑指offer】之栈的压入弹出序列
- 北京哪些医院不用特意选择就可用社保卡直接就医?
- renderscript
- 使用DBMS_JOB包创建ORACLE定时任务
- DP合集
- 软考 -> 网络中各种交换设备
- 剑指offer:栈的压力、弹出序列
- css 底部固定不起作用
- MySQL触发器和Windows计划任务结合使用达到定时触发的效果
- POJ1018
- Linux CentOS PhpMyAdmin安装
- [Wikioi 1220]数字三角形---两种不同的解法(复习)
- KMP字符串模式匹配详解
- 微软中国:对政府禁装Win8感到非常意外
- 时间工具类