leetcode : valid binary search tree
不能通过 当元素中 有 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的更多相关文章
- [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 ...
- LeetCode: Validata Binary Search Tree
LeetCode: Validata Binary Search Tree Given a binary tree, determine if it is a valid binary search ...
- [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 ...
- 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 ...
- LeetCode: Validate Binary Search Tree 解题报告
Validate Binary Search Tree Given a binary tree, determine if it is a valid binary search tree (BST) ...
- 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 ...
- [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 ...
- LeetCode Closest Binary Search Tree Value II
原题链接在这里:https://leetcode.com/problems/closest-binary-search-tree-value-ii/ 题目: Given a non-empty bin ...
- [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 ...
随机推荐
- PHP simplexml_load_string 过滤<![CDATA[XXXX]]>
首先说说过滤<![CDATA[XXXX]]>干嘛用的. 这东西主要是防止XML里面嵌套HTML标签导致XML样式错乱的. 过滤很简单: $response = str_replace( a ...
- css百宝箱
关于css百宝箱? 在前端学习中,总会遇到零星的知识点,小技巧,这些知识点小到不至于用一片博客写出来,遇到时网上查询一下或许也能搞定,但不一定能记住,所以这篇博客就用来记录那些散落的知识点,积少成多, ...
- java调用html模板发送html内容的邮件
在项目需要发送邮件,普通内容的邮件觉得太单调.太丑,没逼格,所以说直接把用到的邮件内容做成一个html模板,发送之前将对应参数替换掉,发送html内容的高逼格邮件. 首先需要引用jar包,这就不多说了 ...
- Atitit.jsou html转换纯文本 java c# php
Atitit.jsou html转换纯文本 java c# php 1. 原理<p> <h> <li><div> 等lable转换为回车1 2. 调用2 ...
- “Stamping” PDF Files Downloaded from SharePoint 2010
http://blog.falchionconsulting.com/index.php/2012/03/stamping-pdf-files-downloaded-from-sharepoint-2 ...
- C标准库<assert.h>实现
本文地址:http://www.cnblogs.com/archimedes/p/c-library-assert.html,转载请注明源地址. 1.背景知识 头文件<assert.h>唯 ...
- Objective-c 基础框架(初学者-总结)
一个框架其实就是一个软件包,它包含了多个类.Mac 操作系统提供了几十个框架,主要帮助开发者快速的在Mac 系统上开发应用程序.其中包括一些基础框架,就是为所有程序开发提供基础的框架,其中几个常用的类 ...
- IOS开发--常用的基本GDB命令
gdb不是万能的,可是没有gdb却是万万不能的.这里给大家简单介绍下iOS开发中最基本的gdb命令. po po是print-object的简写,可用来打印所有NSObject对象.使用举例如下: ( ...
- Silverlight项目笔记8:层次布局、客户端读取shp、ExecuteCountAsync、柱状图、url传参
1.层次布局 由于地图窗口和菜单栏都在一个父容器内,在浏览器缩小到一定程度点击地图弹出infoWindow时,会出现菜单栏遮挡infoWindow中间部分的现象,于是通过设置Canvas.ZIndex ...
- Sql server存储过程中常见游标循环用法
用游标,和WHILE可以遍历您的查询中的每一条记录并将要求的字段传给变量进行相应的处理 DECLARE ), ), @A3 INT DECLARE YOUCURNAME CURSOR FOR SELE ...