不能通过 当元素中 有 val == INT_MAX 或者  val == INT_MIN

/**
* 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 {
public:
bool isValidBST(TreeNode* root) {
if(root==NULL) return true;
return isv(root,INT_MIN,INT_MAX);
}
bool isv(TreeNode * root , int min ,int max)
{
if(root==NULL) return true;
if(root->left!=NULL &&( root->val<= root->left->val||root->left->val<=min)) return false;
if(root->right!=NULL&&( root->val>=root->right->val||root->right->val>=max)) return false;
return isv(root->left,min,root->val)&&isv(root->right,root->val,max);
}
};

  

leetcode : valid binary search tree的更多相关文章

  1. [LeetCode] Validate Binary Search Tree 验证二叉搜索树

    Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as ...

  2. LeetCode: Validata Binary Search Tree

    LeetCode: Validata Binary Search Tree Given a binary tree, determine if it is a valid binary search ...

  3. [LeetCode] Validate Binary Search Tree (两种解法)

    Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as ...

  4. Leetcode Validate Binary Search Tree

    Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as ...

  5. LeetCode: Validate Binary Search Tree 解题报告

    Validate Binary Search Tree Given a binary tree, determine if it is a valid binary search tree (BST) ...

  6. LeetCode: Validate Binary Search Tree [098]

    [题目] Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defin ...

  7. [LeetCode] Closest Binary Search Tree Value II 最近的二分搜索树的值之二

    Given a non-empty binary search tree and a target value, find k values in the BST that are closest t ...

  8. LeetCode Closest Binary Search Tree Value II

    原题链接在这里:https://leetcode.com/problems/closest-binary-search-tree-value-ii/ 题目: Given a non-empty bin ...

  9. [LeetCode] Closest Binary Search Tree Value 最近的二分搜索树的值

    Given a non-empty binary search tree and a target value, find the value in the BST that is closest t ...

随机推荐

  1. sqlite3之基本操作(二)

    作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! Python自带一个轻量级的关系型数据库SQLite.这一数据库使用SQL语言.S ...

  2. 用EF6更新数据库时出现外键错误解决方式

    在“Package Manager Console”中执行update-database命令,出现异常信息: Introducing FOREIGN KEY constraint 'FK_dbo.Pr ...

  3. .NET Core创建一个控制台(Console)程序

    .NET Core版本:1.0.0-rc2 Visual Studio版本:Microsoft Visual Studio Community 2015 Update 2 开发及运行平台:Window ...

  4. HTML 运算符、类型转换

    1.类型转换: 分为自动转换和强制转换,一般用强制转换. 其他类型转换为整数:parseInt(): 其他类型转换为小数:parseFloat(): 判断是否是一个合法的数字类型:isNaN(): 是 ...

  5. Math对象常用方法汇总

    前几天翻阅<JavaScript权威指南>,看到了Math对象,于是汇总了一下. Math对象不同于其他的对象,它可以说是一个公共数学类,里面有很多数学方法,用于各种数学运算,但是Math ...

  6. SAP技术相关Tcode

    ABAP的常用tcode 开发----------------------------------------------- SE51  屏幕制作 SE91  MESSAGE OBJECT SE80  ...

  7. Atitit.为什么小公司也要做高大上开源项目

    Atitit.为什么小公司也要做高大上开源项目 1. 为什么手头有很多加急的事情还要做高大上开源项目??1 2. 从长远看,发展 高大上开源项目计划对于解决我们在应急项目正面临着的种种严峻问题也大有裨 ...

  8. Windows环境下利用github快速配置git环境

    在windows环境下利用github客户端我们可以直接拥有可视化的界面来管理工程,当然你也可以选择你喜欢的命令行工具来做.今天我分享一个比较快速的方式来配置git环境. 先去下载github的win ...

  9. 应用程序代理AppDelegate解析

    应用程序UIApplication是通过代理和外部交互的,当应用程序生命周期中发生改变时UIApplication就会调用代理对应的方法. @implementation AppDelegate - ...

  10. 【原】macbook不睡眠的排查与解决

    这几天突然发现手上的macbook pro笔记本不能睡眠了,就算合上盖子也是如此.有没有进入睡眠可以观察右下角的呼吸灯,如果呼吸灯常亮则说明有问题.所谓“工欲善其事,必先利其器”,攻城狮想敲更多更好的 ...