不能通过 当元素中 有 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. Window下生成OpenSSL自签证书

    :OPenSSL下载地址:https://www.openssl.org/source/ 编译好的OpenSSL下载地址: http://slproweb.com/products/Win32Open ...

  2. webservice 的wsdl文件生成客户端java类

    提供两个方法: 第一个: 发布webservice项目后, 地址栏地址  http://localhost:8888/lxitedu.webservice.cxf-ch2/services/userS ...

  3. SAP数据更新的触发

    SAP 应用系统架构         应用层运行着DIALOG进程,每个DIALOG进程绑定一个数据库进程,DIALOG进程与GUI进行通信,每次GUI向应用服务器发送请求时都会通过dispatche ...

  4. C++引用笔记

    1.什么是引用: 百度百科里的解释:引用就是某一变量(目标)的一个别名,对引用的操作与对变量直接操作完全一样.用&符号表示 举例: using namespace std; int _tmai ...

  5. Spark调优

    因为Spark是内存当中的计算框架,集群中的任何资源都会让它处于瓶颈,CPU.内存.网络带宽.通常,内存足够的情况之下,网络带宽是瓶颈,这时我们就需要进行一些调优,比如用一种序列化的方式来存储RDD来 ...

  6. JAVA-使用commos-fileupload实现文件上传与下载

    一文件的上传 实体类 在CODE上查看代码片派生到我的代码片 import java.sql.Timestamp; /** * * @Decription 文件上传实体类 * @author 刘楠 * ...

  7. Xcode找Library位置

  8. Silverlight项目笔记2:.svc处理程序映射缺失导致的WCF RIA Services异常

    在确定代码.编译结果和数据库都正常的情况下,无法从数据库取到数据.错误提示:Sysyem.Net.WebException:远程服务器返回了错误:NotFound,监听发现请求数据库的服务异常,访问相 ...

  9. GCD编程 之 略微提高篇

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

  10. javascript之工厂方式定义对象

    每一个函数对象都有一个length属性,表示该函数期望接收的参数个数. <html> <head> <script type="text/javascript& ...