剑指Offer:二叉搜索树的后序遍历序列
来源:互联网 发布:linux 调用中文输入法 编辑:程序博客网 时间:2024/06/02 01:58
题目描述
输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历的结果。如果是则输出Yes,否则输出No。假设输入的数组的任意两个数字都互不相同。
class Solution { bool judge(vector<int>& a, int l, int r){ if(l >= r) return true; int i = r; while(i > l && a[i - 1] > a[r]) --i; for(int j = i - 1; j >= l; --j) if(a[j] > a[r]) return false; return judge(a, l, i - 1) && (judge(a, i, r - 1)); }public: bool VerifySquenceOfBST(vector<int> a) { if(!a.size()) return false; return judge(a, 0, a.size() - 1); }};
0 0
- 剑指offer:二叉搜索树的后序遍历序列
- 【剑指offer】二叉搜索树的后序遍历序列
- 剑指offer--二叉搜索树的后序遍历序列
- 剑指Offer-->二叉搜索树的后序遍历序列
- 《剑指offer》二叉搜索树的后序遍历序列
- 【剑指Offer】二叉搜索树的后序遍历序列
- 剑指offer--二叉搜索树的后序遍历序列
- 剑指 offer:二叉搜索树的后序遍历序列
- 剑指offer:二叉搜索树的后序遍历序列
- 【剑指offer】二叉搜索树的后序遍历序列
- 二叉搜索树的后序遍历序列||剑指offer
- 剑指offer-二叉搜索树的后序遍历序列
- 剑指offer 二叉搜索树的后序遍历序列
- 剑指offer 二叉搜索树的后序遍历序列
- 剑指offer:二叉搜索树的后序遍历序列
- [剑指offer]二叉搜索树的后序遍历序列
- 《剑指offer》-二叉搜索树的后序遍历序列
- 【剑指offer】二叉搜索树的后序遍历序列
- Android ListView封装(代码优化):抽取方法共性,封装 BaseAdapter 和 ViewHolder
- 初涉Rx套餐 之RxBinding(让你的事件流程更清晰)
- ubantu下最强最全Git入门
- 按成绩蛇形分班算法
- 5.单件模式(Singleton Pattern)
- 剑指Offer:二叉搜索树的后序遍历序列
- Codeforces Round #239 (Div. 2) C Triangle(暴力)
- java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver问题解决
- LeetCode - Longest Substring Without Repeating Characters
- iptables中ULOG和NFLOG实现分析
- 一台电脑同时运行多个tomcat
- Oracle 使用scott用户登录提示密码过期
- Servlet之Filter过滤器
- 150. Evaluate Reverse Polish Notation