Leetcode 98
/**
* 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的更多相关文章
- [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 ...
- [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 ...
- LeetCode 98. 验证二叉搜索树 | Python
98. 验证二叉搜索树 题目来源:https://leetcode-cn.com/problems/validate-binary-search-tree 题目 给定一个二叉树,判断其是否是一个有效的 ...
- Java实现 LeetCode 98 验证二叉搜索树
98. 验证二叉搜索树 给定一个二叉树,判断其是否是一个有效的二叉搜索树. 假设一个二叉搜索树具有如下特征: 节点的左子树只包含小于当前节点的数. 节点的右子树只包含大于当前节点的数. 所有左子树和右 ...
- 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 ...
- 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 ...
- LeetCode 98 验证二叉搜索树
题目: 给定一个二叉树,判断其是否是一个有效的二叉搜索树. 假设一个二叉搜索树具有如下特征: 节点的左子树只包含小于当前节点的数. 节点的右子树只包含大于当前节点的数. 所有左子树和右子树自身必须也是 ...
- [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 ...
- [LeetCode] 98. Validate Binary Search Tree(是否是二叉搜索树) ☆☆☆
描述 解析 二叉搜索树,其实就是节点n的左孩子所在的树,每个节点都小于节点n. 节点n的右孩子所在的树,每个节点都大于节点n. 定义子树的最大最小值 比如:左孩子要小于父节点:左孩子n的右孩子要大于n ...
随机推荐
- Sublime text 3 汉化教程
首先,需要安装Package Control 启动并进入sublime主界面,打开Sublime Text的控制台(快捷键 ctrl + ~) 然后我们到Package Control官方网站,复制s ...
- UI、JS框架----Bootstrap、Metro
Bootstrap Datagrid EasyUI Metro bootstrap Datepicker Editable for Bootstrap:bootstrap-editable.js X- ...
- 操作 frames 框架下的 dom 内容。
2016-12-30 框架名: var obj=$(window.frames["wangpan"].document).find("a[menu=download_on ...
- linux运行lnmp 出现502错误
之前遇到的问题: 安装好之后访问域名出现502错误,打开html文件正常,说明是php出现问题.在wwwlog文件夹查看nginx日志,发现报错原因是找不到/var/run/php5-fpm.sock ...
- phantomjs 下载
http://phantomjs.org/download.html
- 3. 使用vue-cli创建项目
eslint: 用来做项目编码规范检查的工具基本原理: 定义了很多规则, 检查项目的代码一旦发现违背了某个规则就输出相应的提示信息有相应的配置, 可定制检查 1. 创建项目 vue脚手架(vue-cl ...
- Python 函数也是一种对象
函数也是一种对象 func = lambda x, y: x+y print func(3, 4) def func(x, y): return x+y print func(3, 4) 效果相同. ...
- in_array的三个参数
needle 待搜索的值. haystack 待搜索的数组. strict 如果第三个参数 strict 的值为 TRUE 则 in_array() 函数还会检查 needle 的类型是否和 hays ...
- PostgreSQL 扩展开发基础教程
搭建基础结构 安装扩展 sudo apt-get install postgresql-contribcreatedb stupsql stucreate extension pg_buffercac ...
- Spark SQL笔记
HDFS HDFS架构 1.Master(NameNode/NN) 对应 N个Slaves(DataNode/NN)2.一个文件会被拆分成多个块(Block)默认:128M例: 130M ==> ...