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 ...
随机推荐
- (转载)c# winform comboBox的常用一些属性和用法
comboBox的常用一些属性和用法 [1].控件的默认值怎么设? this.comboBox1.Text = "请选择港口"; comboBox1.Items.Add(" ...
- kubernetes 实战3_命令_Configure Pods and Containers
Configure a Pod to Use a PersistentVolume for Storage how to configure a Pod to use a PersistentVolu ...
- StringBuilder的三种删除方法比较
分别用一千万次循环来比较StringBuilder的三种删除方法所用时间 未避免偶然性,再循环一百次来比较总时间 --主类 public class StringBuilderRemove { pub ...
- Tomcat的manager app管理web项目
1.在浏览器地址栏输入http://localhost:8080/进入,如下图所示: 2.在点击Manager App 前,首次使用则需要对tomcat目录下的conf/tomcat-users.xm ...
- 【Python】【有趣的模块】【requests】【一】HTTP头信息总结
[HTTP请求 == 请求行 + 消息报头 + 请求正文 ] 请求行:Method Request-URL HTTP-Version CRLF HTTP协议定义了许多与服务器交互的方法 ① PUT:请 ...
- PL/SQL Developer过期解决方法
参考资料: plsql过期解决方法 plsql永久注册码适用个版本 方法一: 1.首先,登陆PL/SQL Developer,PL/SQL Developer要到期了 2.输入指令“regedit”打 ...
- 【BZOJ】3139: [Hnoi2013]比赛
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3139 可以发现,答案之和得分的序列有关,而且和序列中每个元素的顺序无关.考虑HASH所有的 ...
- 使用Coding体验小记
https://coding.net/ 写了些小程序后放在github上托管,并用gitpages展示. 今天发现用git pages展示的网页网络特别不稳定,时常会出现网页打不开的现象. 之前一直通 ...
- Oracle(字符函数)
单行函数语法: 语法:funcation_name(列 | 表达式[, 参数1, 参数2]) 单行函数主要分为以下几种: 字符函数:接收数据返回具体的字符信息 数值函数:对数字进行处理,例如:四舍五入 ...
- libxml2的xpath检索中文
ZC: xmlXPathEvalExpression(...) 当 xpath的字符串中 包含中文的时候,返回NULL,暂时不知道该怎么处理了... ZC: 下面是测试的一些代码/文件,留着以后再研究 ...