剑指offer--二叉搜索树的后序遍历序列
来源:互联网 发布:苹果mac输入法设置 编辑:程序博客网 时间:2024/06/06 02:13
题目描述
输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历的结果。如果是则输出Yes,否则输出No。假设输入的数组的任意两个数字都互不相同。
public class Solution { public boolean VerifySquenceOfBST(int [] sequence) { return Verification(0,sequence.length-1,sequence); } private boolean Verification(int start,int end,int[] array){ if(array.length == 0) return false; if( start >= end ) return true; int i; for(i = start; i < end; i++){ if(array[i] > array[end]) break; } for (;i < end; i++){ if(array[i] < array[end]) return false; } return Verification(start,end-1,array); }}
对于二叉排序树的后序遍历,去掉最后一个元素之后,前面的数字还可以分为左右两段。前面一段比最后一位小,后面一段比最后一段大。
代码写得好像有问题…..
阅读全文
0 0
- 剑指offer:二叉搜索树的后序遍历序列
- 【剑指offer】二叉搜索树的后序遍历序列
- 剑指offer--二叉搜索树的后序遍历序列
- 剑指Offer-->二叉搜索树的后序遍历序列
- 《剑指offer》二叉搜索树的后序遍历序列
- 【剑指Offer】二叉搜索树的后序遍历序列
- 剑指offer--二叉搜索树的后序遍历序列
- 剑指 offer:二叉搜索树的后序遍历序列
- 剑指offer:二叉搜索树的后序遍历序列
- 【剑指offer】二叉搜索树的后序遍历序列
- 二叉搜索树的后序遍历序列||剑指offer
- 剑指offer-二叉搜索树的后序遍历序列
- 剑指offer 二叉搜索树的后序遍历序列
- 剑指offer 二叉搜索树的后序遍历序列
- 剑指offer:二叉搜索树的后序遍历序列
- [剑指offer]二叉搜索树的后序遍历序列
- 《剑指offer》-二叉搜索树的后序遍历序列
- 【剑指offer】二叉搜索树的后序遍历序列
- Android开发-SQLite数据库
- 转换函数笔记2----C++学习之路
- 数据类型的取值范围计算
- 自定义组合控件,自定义View,接口点击事件
- 自定义一个进度条+百分比
- 剑指offer--二叉搜索树的后序遍历序列
- 职业倦怠
- Retrofit简单实用
- 在BaseAdapter中 list优化 + 网络 获取图片利用线程传输
- 漫谈 WebRTC 一: 何谓Simulcast, WebRTC中的Simulcast
- 从源码看集合ArrayList
- 比较有索引和无索引的查询速度(在mysql数据库中)
- css js添加
- 115.2