LeetCode #938. Range Sum of BST 二叉搜索树的范围和
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 二叉搜索树的范围和的更多相关文章
- Leetcode938. Range Sum of BST二叉搜索树的范围和
给定二叉搜索树的根结点 root,返回 L 和 R(含)之间的所有结点的值的和. 二叉搜索树保证具有唯一的值. 示例 1: 输入:root = [10,5,15,3,7,null,18], L = 7 ...
- [LeetCode] Minimum Absolute Difference in BST 二叉搜索树的最小绝对差
Given a binary search tree with non-negative values, find the minimum absolute difference between va ...
- Leetcode 938. Range Sum of BST
import functools # Definition for a binary tree node. # class TreeNode(object): # def __init__(self, ...
- 【Leetcode_easy】938. Range Sum of BST
problem 938. Range Sum of BST 参考 1. Leetcode_easy_938. Range Sum of BST; 完
- LeetCode:将有序数组转换为二叉搜索树【108】
LeetCode:将有序数组转换为二叉搜索树[108] 题目描述 将一个按照升序排列的有序数组,转换为一棵高度平衡二叉搜索树. 本题中,一个高度平衡二叉树是指一个二叉树每个节点 的左右两个子树的高度差 ...
- 数据结构中很常见的各种树(BST二叉搜索树、AVL平衡二叉树、RBT红黑树、B-树、B+树、B*树)
数据结构中常见的树(BST二叉搜索树.AVL平衡二叉树.RBT红黑树.B-树.B+树.B*树) 二叉排序树.平衡树.红黑树 红黑树----第四篇:一步一图一代码,一定要让你真正彻底明白红黑树 --- ...
- [LeetCode] Serialize and Deserialize BST 二叉搜索树的序列化和去序列化
Serialization is the process of converting a data structure or object into a sequence of bits so tha ...
- [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 ...
- [LeetCode] Recover Binary Search Tree 复原二叉搜索树
Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing ...
随机推荐
- 确定Git与GitHub连接起来
1.准备工作 1)下载Git 2)注册GitHub 3)将Git与GitHub链接起来 1.获取ssh密匙 2.GitHub里 找到settings 填入密匙 2.正式开始 1)确定Git与GitHu ...
- ReactiveObjC(RAC)的使用汇总
RAC 指的就是 RactiveCocoa ,是 Github 的一个开源框架,能够帮我们提供大量方便的事件处理方案,让我们更简单粗暴地去处理事件,现在分为 ReactiveObjC 和 Reacti ...
- 【记录】git error:bad signature 解决方法
今天提交git 的时候出现 bad signature 错误,意思是git下的index文件损坏了,需要重新生成下 error: bad signature fatal: index file cor ...
- C#.Net 调用Java的Web Service
首先,得有一个web service地址:http://www.baiduc.om/XXServices?wsdl 然后在.net 项目中添加Web引用,并把地址给它输进去 第三.编码: using ...
- linux7 grub配置文件 linux6 grub配置文件
在 grub 的 kernel 配置后面,添加 acpi_pad.disable=1 重启机器之后,开机就不会自动加载 acpi_pad 模块 一:linux6 [root@node2 ~]# cat ...
- selenium下拉菜单
from selenium.webdriver.support.select import Selectdef select_value(self, css, value): ''' 选中 ...
- mvn 打包排除test
mvn clean package compile -Dmaven.test.skip=true
- 树形dp专栏
前言 自己树形dp太菜了,要重点搞 219D Choosing Capital for Treeland 终于自己做了一道不算那么毒瘤的换根dp 令 \(f[u]\) 表示以 \(u\) 为根,子树内 ...
- VUE的系统指令
1. -text原样渲染,渲染文本 2.-html HTML渲染页面 举例: <!doctype html> <html lang="en"> < ...
- Eclipse 4.9 创建springboot项目步骤
上一篇文章写了eclipse安装STS. 现在创建Spring Starter Project 具体步骤如下: 1.等你安装好STS后,就在Eclipse > File >New 选择 ...