https://leetcode-cn.com/problems/range-sum-of-bst/

二叉树中序遍历

二叉搜索树性质:一个节点大于所有其左子树的节点,小于其所有右子树的节点

 /**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
class Solution {
public int rangeSumBST(TreeNode root, int L, int R) {
int result = 0; if (root != null) {
if (root.val >= L && root.val <= R) {
result += root.val;
}
result += rangeSumBST(root.left, L, R);
result += rangeSumBST(root.right, L, R);
}
return result;
}
}

LeetCode #938. Range Sum of BST 二叉搜索树的范围和的更多相关文章

  1. Leetcode938. Range Sum of BST二叉搜索树的范围和

    给定二叉搜索树的根结点 root,返回 L 和 R(含)之间的所有结点的值的和. 二叉搜索树保证具有唯一的值. 示例 1: 输入:root = [10,5,15,3,7,null,18], L = 7 ...

  2. [LeetCode] Minimum Absolute Difference in BST 二叉搜索树的最小绝对差

    Given a binary search tree with non-negative values, find the minimum absolute difference between va ...

  3. Leetcode 938. Range Sum of BST

    import functools # Definition for a binary tree node. # class TreeNode(object): # def __init__(self, ...

  4. 【Leetcode_easy】938. Range Sum of BST

    problem 938. Range Sum of BST 参考 1. Leetcode_easy_938. Range Sum of BST; 完

  5. LeetCode:将有序数组转换为二叉搜索树【108】

    LeetCode:将有序数组转换为二叉搜索树[108] 题目描述 将一个按照升序排列的有序数组,转换为一棵高度平衡二叉搜索树. 本题中,一个高度平衡二叉树是指一个二叉树每个节点 的左右两个子树的高度差 ...

  6. 数据结构中很常见的各种树(BST二叉搜索树、AVL平衡二叉树、RBT红黑树、B-树、B+树、B*树)

    数据结构中常见的树(BST二叉搜索树.AVL平衡二叉树.RBT红黑树.B-树.B+树.B*树) 二叉排序树.平衡树.红黑树 红黑树----第四篇:一步一图一代码,一定要让你真正彻底明白红黑树 --- ...

  7. [LeetCode] Serialize and Deserialize BST 二叉搜索树的序列化和去序列化

    Serialization is the process of converting a data structure or object into a sequence of bits so tha ...

  8. [LeetCode] 285. Inorder Successor in BST 二叉搜索树中的中序后继节点

    Given a binary search tree and a node in it, find the in-order successor of that node in the BST. Th ...

  9. [LeetCode] Recover Binary Search Tree 复原二叉搜索树

    Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing ...

随机推荐

  1. Python之路-变量和基本数据类型详解(变量、数据类型、)

    一.注释 注释的作用: 增加程序的可读性 作为调试用 提高团队的合作效率 注释的分类 1.单行注释 以井号(#)开头,右边的所有内容当做说明 2.多行注释 以三对单引号(’’’注释内容’’’)将注释包 ...

  2. R语言封装函数

    R语言封装函数 原帖见豆瓣:https://www.douban.com/note/279077707/ 一个完整的R函数,需要包括函数名称,函数声明,函数参数以及函数体几部分. 1. 函数名称,即要 ...

  3. linux系统安装telnet服务

    linux安装telnet 安装前准备工作 1.安装telnet服务需要三个软件包:telnet.telnet-server和xinetd包. telnet,telnet-sever,xinetd软件 ...

  4. navicat的使用(测试库和正式库同步)以及用plsql改表字段属性

    说明:数据库的操作,除了查询,最好先做好备份,比如数据同步.更新.修改或删除之类的: netstat -antp   查看mysql端口 firewall -cmd --list-all    查看防 ...

  5. Dubbo学习-4-dubbo简单案例-2-服务提供者和消费者配置

    在上一篇帖子的基础上,开始使用dubbo来实现RPC调用: 根据dubbo的架构图可知,需要做以下几件事情: 1.将服务提供者注册到注册中心(暴露服务) (1)引入dubbo依赖, 这里依赖2.6.2 ...

  6. ht-5 treemap特性

    (1)TreeMap类通过使用红黑树实现Map接口 (2)TreeMap提供按排序顺序存储键值对的有效手段,同时允许快速检索 (3)不同于散列映射,树映射保证它的元素按键的自然顺序升序排列 (4)Tr ...

  7. Log4d:Error:Could not instantiate class[com.mapgis.util.tools.JDBCExtAppender]

    https://blog.csdn.net/gikieng/article/details/47150567  https://blog.alswl.com/2018/03/sql-server-mi ...

  8. (3)狄泰软件学院C++课程学习剖析一

    深度剖析C++第一部分 1.类是一种模型,这种模型可以创建出一个对应的实体.有了类不一定有对应的实体,但是一个实体必定属于某一个类. 2.类用于抽象的描述 一类事物所持有的属性和行为:对象是具体的事物 ...

  9. python-zx笔记9-单元测试

    unittest核心要素 1.TestCase 一个TestCase的实例就是一个测试用例.什么是测试用例呢?就是一个完整的测试流程,包括测试前准备环境的搭建(setUp),执行测试代码(run),以 ...

  10. 纯css实现瀑布流(multi-column多列及flex布局)

    瀑布流的布局自我感觉还是很吸引人的,最近又看到实现瀑布流这个做法,在这里记录下,特别的,感觉flex布局实现瀑布流还是有点懵的样子,不过现在就可以明白它的原理了 1.multi-column多列布局实 ...