/**
* 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) {
vector<int> res;
int flag = ;
long num = LONG_MIN;
dfs(root,num,flag);
return flag;
} void dfs(TreeNode* root,long& maxnum,int& flag){
if(root == NULL) return;
if(root->left) dfs(root->left,maxnum,flag);
if(root->val > maxnum){
maxnum = root->val;
}
else{
flag = ;
}
if(root->right) dfs(root->right,maxnum,flag);
}
};

__卡边界有点恶心,改成LONG就好了

Leetcode 98的更多相关文章

  1. [LeetCode] 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 ...

  2. [LeetCode] 98. Validate Binary Search Tree_Medium

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

  3. LeetCode 98. 验证二叉搜索树 | Python

    98. 验证二叉搜索树 题目来源:https://leetcode-cn.com/problems/validate-binary-search-tree 题目 给定一个二叉树,判断其是否是一个有效的 ...

  4. Java实现 LeetCode 98 验证二叉搜索树

    98. 验证二叉搜索树 给定一个二叉树,判断其是否是一个有效的二叉搜索树. 假设一个二叉搜索树具有如下特征: 节点的左子树只包含小于当前节点的数. 节点的右子树只包含大于当前节点的数. 所有左子树和右 ...

  5. Leetcode 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 ...

  6. leetcode 98 Validate Binary Search Tree ----- java

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

  7. LeetCode 98 验证二叉搜索树

    题目: 给定一个二叉树,判断其是否是一个有效的二叉搜索树. 假设一个二叉搜索树具有如下特征: 节点的左子树只包含小于当前节点的数. 节点的右子树只包含大于当前节点的数. 所有左子树和右子树自身必须也是 ...

  8. [leetcode]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 ...

  9. [LeetCode] 98. Validate Binary Search Tree(是否是二叉搜索树) ☆☆☆

    描述 解析 二叉搜索树,其实就是节点n的左孩子所在的树,每个节点都小于节点n. 节点n的右孩子所在的树,每个节点都大于节点n. 定义子树的最大最小值 比如:左孩子要小于父节点:左孩子n的右孩子要大于n ...

随机推荐

  1. numa.h:No such file or directory 解决方法

    参考: numa.h:No such file or directory numa.h:No such file or directory 解决方法 Ubuntu: $ apt-get install ...

  2. .Net MVC关于子页面引用js库问题

    layout页面中的配置: @RenderSection("scripts", required: false) @RenderSection("Styles" ...

  3. vue--toutiao

    git:https://github.com/vinieo/vue-toutiao 顶部导航栏 内容 底部导航按钮 组件

  4. 关于Tortoise git汉化包装了,不管用,仍然是英文菜单的问题记录

    今天在装小乌龟(TortoiseGIT)碰到了安装中文语言包不管用的情况,后来在几番折腾之后总算搞定了,但是具体哪一步搞定的,目前原因还不清楚,所以把搞定的过程记录下,留作后用: 1.Tortoise ...

  5. Django本地开发,引用静态文件,火狐浏览器不能访问静态文件,谷歌浏览器却能访问静态文件

    查了一下是settings.py设置问题 # Static files (CSS, JavaScript, Images)# https://docs.djangoproject.com/en/1.1 ...

  6. 关于python的基础知识

    一,编程语言的类型: 1.编译型 2.解释型 3.静态语言 4.动态语言 5.强类型定义语言 6.弱类型定义语言 编译型vs解释型 编译型: 优点:编译器一般会有预编译的过程对代码进行优化.因为编译只 ...

  7. Python中cPickle

    cPickle模块: 在python中,一般可以使用pickle类来进行python对象序列化,而cPickle提供了一个更快速简单的接口,如python文档所说:“cPickle - A faste ...

  8. cocos2dx lua 绑定之一:自动绑定自定义类中的函数

    cococs2dx 3.13.1 + vs2013 + win10 1.首先定义C++类Student 在cocos2d-x\cocos文件夹下新建一个user_define的文件夹放置两个文件. 注 ...

  9. 非递归遍历二叉树Java实现

    2018-10-03 20:16:53 非递归遍历二叉树是使用堆栈来进行保存,个人推荐使用双while结构,完全按照遍历顺序来进行堆栈的操作,当然在前序和后序的遍历过程中还有其他的压栈流程. 一.Bi ...

  10. python中configparser模块的使用

    configparser模块用于生成和修改常见配置文档,当前模块的名称在 python 3.x 版本中变更为 configparser. 首先要写一个如下所示的配置文件: [DEFAULT] serv ...