剑指offer刷题之java实现的二叉搜索树的后序遍历序列
来源:互联网 发布:软件产品设计文档模板 编辑:程序博客网 时间:2024/05/20 02:25
package mine;/** * * @author毛二 * @data 2015-8-9 * @comments二叉搜索树的后序遍历序列 * 输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历的结果。 * 如果是则输出Yes,否则输出No。假设输入的数组的任意两个数字都互不相同。 */public class PostSeqOfTwoSearchTree { public static boolean VerifySquenceOfBST(int [] sequence) { //边界值判断时,不光要判断数组是否为null,还有可能长度为零。 if(sequence == null || sequence.length == 0) return false; return oneVerifySquenceOfBST(sequence,0,sequence.length-1); } public static boolean oneVerifySquenceOfBST(int[] a,int low,int high){ boolean f = true; int l = low,h = high-1; System.out.println("start: "+"l = "+l+" h = "+h); if(low <high){ while(l<h && a[l]<a[high]) l++; while(l<h && a[h]>a[high]) h--; System.out.println("l = "+l+" h = "+h); if(l==h){ return oneVerifySquenceOfBST(a,low,l-1)&&oneVerifySquenceOfBST(a,l,high-1); } else { f = false; } } return f; } public static void main(String[] args) {int[] a ={};//= null;//{7,4,6,5};//{5,7,6,9,11,10,8};System.out.println(VerifySquenceOfBST(a));}}
0 0
- 剑指offer刷题之java实现的二叉搜索树的后序遍历序列
- 二叉搜索树的后序遍历序列-剑指offer(java实现)
- 剑指offer--面试题24:二叉搜索树的后序遍历序列--Java实现
- 剑指offer第二十三题【二叉搜索树的后序遍历序列】c++实现
- 剑指offer:二叉搜索树的后序遍历序列
- 【剑指offer】二叉搜索树的后序遍历序列
- 剑指offer--二叉搜索树的后序遍历序列
- 剑指Offer-->二叉搜索树的后序遍历序列
- 《剑指offer》二叉搜索树的后序遍历序列
- 【剑指Offer】二叉搜索树的后序遍历序列
- 剑指offer--二叉搜索树的后序遍历序列
- 剑指 offer:二叉搜索树的后序遍历序列
- 剑指offer:二叉搜索树的后序遍历序列
- 【剑指offer】二叉搜索树的后序遍历序列
- 二叉搜索树的后序遍历序列||剑指offer
- 剑指offer-二叉搜索树的后序遍历序列
- 剑指offer 二叉搜索树的后序遍历序列
- 剑指offer 二叉搜索树的后序遍历序列
- tcp/ip学习笔记
- 第一周工作总结及计划表
- 代码获取Android版本等信息
- 红黑二叉查找树
- gerrit H2 数据库管理
- 剑指offer刷题之java实现的二叉搜索树的后序遍历序列
- 提取最长转录本的代码
- 一步一步在ubuntu上安装即时通讯服务器-Openfire
- poj 2387 Til the Cows Come Home
- 重复子串问题(五):求最长回文字符子串
- 动态规划专题之zoj1013
- B. Berland National Library
- 浅析CVE-2015-3636
- Ubuntu 安装mysql和简单操作