class Solution {
public:
vector<int> V;
void postTree(TreeNode* node) {
if (node != NULL) {
if (node->left != NULL) {
postTree(node->left);
}
V.push_back(node->val);
if (node->right != NULL) {
postTree(node->right);
}
}
}
bool isValidBST(TreeNode* root) {
postTree(root);
for (int i = ; i < V.size(); i++) {
if (V[i] <= V[i - ]) {
return false;
}
}
return true;
}
};

补充一个python的实现:

 class Solution:
def __init__(self):
self.lists = [] def inOrder(self,root):
if root != None:
if root.left != None:
self.inOrder(root.left)
self.lists.append(root.val)
if root.right != None:
self.inOrder(root.right) def isValidBST(self, root: 'TreeNode') -> 'bool':
self.inOrder(root)
n = len(self.lists)
for i in range(n-):
if self.lists[i] >= self.lists[i+]:
return False
return True

leetcode98的更多相关文章

  1. leetcode98 Validate Binary Search Tree

    题目: Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is define ...

  2. (BST 递归) leetcode98. Validate Binary Search Tree

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

  3. [Swift]LeetCode98. 验证二叉搜索树 | 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. LeetCode98. 验证二叉搜索树

     验证二叉搜索树  *  * https://leetcode-cn.com/problems/validate-binary-search-tree/description/  *  * algor ...

  5. Leetcode98. Validate Binary Search Tree验证二叉搜索树

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

  6. [LeetCode98]98. Validate Binary Search Tree判断二叉搜索树

    判断二叉搜索树的方法是: 中序遍历形成递增序列 //全局变量记录中序遍历产生的序列,因为要递归,所以要用全局变量 List<Integer> list = new ArrayList< ...

  7. leetcode1305 All Elements in Two Binary Search Trees

    """ Given two binary search trees root1 and root2. Return a list containing all the i ...

  8. leetcode_二叉树篇_python

    主要是深度遍历和层序遍历的递归和迭代写法. 另外注意:因为求深度可以从上到下去查 所以需要前序遍历(中左右),而高度只能从下到上去查,所以只能后序遍历(左右中). 所有题目首先考虑root否是空.有的 ...

  9. LeetCode通关:连刷三十九道二叉树,刷疯了!

    分门别类刷算法,坚持,进步! 刷题路线参考:https://github.com/youngyangyang04/leetcode-master 大家好,我是拿输出博客来督促自己刷题的老三,这一节我们 ...

随机推荐

  1. 20175224 2018-2019-2 《Java程序设计》第二周学习总结

    教材学习内容总结 本周对教材的第二第三章进行了学习,通过阅读教材,我发现java和c语言在相似的基础上还是有很多不同的地方,以下是我对这周学习知识的一些总结. 2.1 java标识符中的字母是区分大小 ...

  2. Linux:挂载、卸载光盘

    挂载.卸载光盘 前提准备: 已经安装好虚拟机 安装好的虚拟机与镜像系统最好一致 前提配置 1.选择虚拟机 2.选择设置 3.选择CD/DVD 4.选择ISO镜像文件,选择设备状态,都勾选 5.ps如果 ...

  3. 基于Verilog的串口发送程序

    一.模块框图及基本思路 tx_bps_module:波特率时钟产生模块 tx_control_module:串口发送的核心控制模块 tx_module:前两个模块的组合 control_module: ...

  4. RPi 3B Aduio 3.5mm output

    /********************************************************************** * RPi 3B Aduio 3.5mm output ...

  5. JAVA高级篇(三、JVM编译机制、类加载机制)

    一.类的加载过程 JVM将类的加载分为3个步骤: 1.装载(Load) 2.链接(Link) 3.初始化(Initialize) 其中 链接(Link)又分3个步骤,如下图所示: 1) 装载:查找并加 ...

  6. 关于windows下的makefile学习

    文中部分引用自:http://bbs.chinaunix.net/forum.php?mod=viewthread&tid=408225 windows下makefile环境配置见于:http ...

  7. jsonify

    在flask中通过响应,将json数据显示在网页中,并且将Content-Type该为application/json格式 1,第一种方法: from flask import jsonify @ap ...

  8. 微信小程序 | 多个按钮或VIEW,切换状态的简单方法(三元)

    wxml文件 wxss文件 js文件

  9. RabbitMQ安装记录(windows10)

    RabbitMQ安装记录(windows10)   一.安装包准备 otp_win64_R16B03.exe(这里使用该版本,不支持ssl) otp_win64_19.0.exe(如果要开启ssl,请 ...

  10. liunx学习笔记(一:常用命令)

    linux: 在学习linux之前我们应该多少了解windows的一些相关操作,linux也就是类似windows的另一种操作系统,用来管理软硬件的一种应用.在windows下你可以通过鼠标点击相关的 ...