[理解leetcode解法]98. Validate Binary Search Tree 判断是否二分查找树
来源:互联网 发布:centos svn 防火墙 编辑:程序博客网 时间:2024/06/15 20:13
98. Validate Binary Search Tree 判断是否二分查找树
#题目
Given a binary tree, determine if it is a valid binary search tree (BST).
Assume a BST is defined as follows:
- The left subtree of a node contains only nodes with keys less than the node's key.
- The right subtree of a node contains only nodes with keys greater than the node's key.
- Both the left and right subtrees must also be binary search trees.
#题解
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
private:
TreeNode* pre;
public:
bool isValidBST(TreeNode* root) {
if(root != NULL){
if(!isValidBST(root->left)){
return false;
}
if(pre != NULL && root -> val <= pre -> val ) return false; //1
pre=root;
if(!isValidBST(root->right)){
return false;
}
return true;
}
return true;
}
};
#题释
//1:
中序遍历
0 0
- [理解leetcode解法]98. Validate Binary Search Tree 判断是否二分查找树
- 【LeetCode】Validate Binary Search Tree 二叉查找树的判断
- Validate Binary Search Tree 判断是否是合法的二分搜索树
- LeetCode(Validate Binary Search Tree) 判断一个二叉树是否是二叉搜索树
- 判断给定二叉树是否是二叉搜索树(LeetCode: Validate Binary Search Tree)
- 判断二叉查找树的合法性 Validate Binary Search Tree
- 【LeetCode】98. Validate Binary Search Tree 解法,中序遍历,搜索二叉树合法性
- Leetcode 98 Validate Binary Search Tree 验证二叉查找树
- 【LeetCode】Validate Binary Search Tree 验证二叉查找树
- LeetCode 98. Validate Binary Search Tree
- [LeetCode]98.Validate Binary Search Tree
- [Leetcode] 98. Validate Binary Search Tree
- LeetCode --- 98. Validate Binary Search Tree
- [leetcode] 98.Validate Binary Search Tree
- [leetcode] 98.Validate Binary Search Tree
- [Leetcode] 98. Validate Binary Search Tree @python
- Leetcode 98. Validate Binary Search Tree
- [LeetCode]98. Validate Binary Search Tree
- zImage与uImage的区别
- JavaScript基础
- Zabbix Graphs汇总
- 拥抱 Android Studio 之三:溯源,Groovy 与 Gradle 基础
- C#跨平台调用接口(URL传参GET调用和Post Json传参调用)
- [理解leetcode解法]98. Validate Binary Search Tree 判断是否二分查找树
- 框架模式 MVC 在Android中的使用
- JSPath基础用法
- RGB与HSB之间的转换公式
- ip冲突和双网卡模式
- ChildViewController
- 关于iOS多线程,你看我就够了
- Tomcat类加载机制
- poj3264 Balanced Lineup(RMQ裸题)