不能通过 当元素中 有 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. [小北De编程手记] : Lesson 01 - Selenium For C# 之 环境搭建

    在我看来一个自动化测试平台的构建,是一种很好的了解开发语言,单元测试框架,自动化测试驱动,设计模式等等等的途径.因此,在下选择了自动化测试的这个话题来和大家分享一下本人关于软件开发和自动化测试的认识. ...

  2. Sigleton 单例模式 的简单应用

    需求:一个简单的后台java程序,收集信息,并将信息发送到远端服务器. 实现:实现一个后台线程,实时处理发送过来的信息,并将信息发送到服务器. 技术要点: 1.单例模式 2.队列 并没有实现全部代码, ...

  3. Webform(简单控件、复合控件)

    一.简单控件: 1.label控件 <asp:Label ID="Label1" runat="server" Text="账 号:" ...

  4. mongodb driver c#语法

    Definitions and BuildersThe driver has introduced a number of types related to the specification of ...

  5. JavaScript的作用域和闭包

    首发于:https://mingjiezhang.github.io/ 闭包和作用域有着千丝万缕的联系. js的作用域 具体的作用域我就不展开叙述了.其中很重要的两点就是:js的作用域链机制和函数词法 ...

  6. SharePoint 自定义WebPart之间的连接

    1.创建SharePoint解决方案,添加两个WebPart分别用来发送和接收: 2.发送值的WebPart需要继承自IWebPartField(当然,根据需要还可以选择IWebPartField,I ...

  7. App开发流程之Xcode配置和本地化

    补充一点遗漏的Xcode配置. 1.偏好设置.Xcode的菜单栏Xcode -> Preference Fonts & Colors可以自定义编码区和控制台的背景.字体. Text Ed ...

  8. GCD编程 之 略微提高篇

    额外任务:学习YouXianMing封装好的GCD源码   1.GCD串行队列与并发队列   串行队列一次只执行一个线程,按照添加到队列的顺序依次执行 并发队列一次可以执行多个线程,线程的执行没有先后 ...

  9. XCode升级到7后,规范注释生成器VVDocumenter插件没有用了,怎么办?

    Xcode更新到7之后,发现很多插件包括规范注释生成器VVDocumenter的插件都没法用了,找遍百度都没有找到成功解决这个问题的方法,然后我突发奇想,把注释也弄进代码模板里.虽然没有插件那样灵活: ...

  10. 在Dynamics CRM 2015中通过3CX插件(以及3CX windows phone)拨出电话

    背景 在On-premises部署的Dynamics CRM中实现通过网页拨通客户电话的功能 要点 3CX 提供了开箱即用的Dynamics CRM Solution,只需要在Microsoft Dy ...