331. Verify Preorder Serialization of a Binary Tree
来源:互联网 发布:淘宝旺铺2016年多少钱 编辑:程序博客网 时间:2024/05/21 13:59
public static boolean isValidSerialization(String preorder) { if(preorder == null || preorder.length() == 0) { return false; }else { Stack<String> stack = new Stack<String>(); String[] str = preorder.split(","); if(str.length == 2) { return false; } int i = 0; boolean is = true; for(i = 0; i < str.length; i++) { if(str[i].equals("#")) { String pc1 = "#"; String pc2 = ""; if(!stack.isEmpty()) { pc2 = stack.peek(); }else { if(i == str.length) { stack.push("#"); break; }else { is =false; break; } } while(pc1.equals("#") && pc1 == pc2) { stack.pop(); if(stack.isEmpty()) { is = false; break; } String cc = stack.peek(); if(cc.equals("#")) { is = false; break; }else { stack.pop(); pc1 = "#"; if(!stack.isEmpty()) { pc2 = stack.peek(); }else { pc2 = ""; break; } } } if(is) { stack.push(pc1); }else { break; } }else { stack.push(str[i]); } } if(!is) { return false; }else { if(stack.isEmpty()) { return false; }else{ String pc = stack.peek(); stack.pop(); if(pc.equals("#") && stack.isEmpty()) { return true; }else { return false; } } } } }
0 0
- Verify Preorder Serialization of a Binary Tree
- Verify Preorder Serialization of a Binary Tree
- Verify Preorder Serialization of a Binary Tree
- Verify Preorder Serialization of a Binary Tree
- Verify Preorder Serialization of a Binary Tree
- Verify Preorder Serialization of a Binary Tree
- Verify Preorder Serialization of a Binary Tree
- Verify Preorder Serialization of a Binary Tree
- Verify Preorder Serialization of a Binary Tree
- Verify Preorder Serialization of a Binary Tree
- 331. Verify Preorder Serialization of a Binary Tree
- leetcode 331. Verify Preorder Serialization of a Binary Tree
- [LeetCode]331. Verify Preorder Serialization of a Binary Tree
- 331. Verify Preorder Serialization of a Binary Tree
- 【LeetCode】331. Verify Preorder Serialization of a Binary Tree
- 331. Verify Preorder Serialization of a Binary Tree
- LeetCode 331. Verify Preorder Serialization of a Binary Tree
- LeetCode *** 331. Verify Preorder Serialization of a Binary Tree
- js生成弹窗样式
- RTMP流媒体使用中的服务器和客户端
- 利用Cookie保存数据,在浏览器页面显示用户上次访问时间
- ubuntu 14.04 64位版本 gcc无法运行 安装ia32-libs提示没有可用的软件包 怎么破
- 第九讲 本地存储
- 331. Verify Preorder Serialization of a Binary Tree
- Java后台框架之一(SpringMVC+MyBatis+Shiro+H5)(0)
- ci表单验证
- 常用类Date时间日期格式
- leetcode——Best Time to Buy and Sell StockⅠ& Ⅱ& Ⅲ & Ⅳ
- bootstrap js控制模态框
- Android bluetooth介绍(一):基本概念及硬件接口
- 8. XSS 攻击
- 杀手数独的计算机求解