题目

 1 class Solution {
2 public:
3 int sum = 0;
4 int rangeSumBST(TreeNode* root, int low, int high) {
5 dfs(root,low,high);
6 return sum;
7 }
8 void dfs(TreeNode* root,int low,int high){
9 if(root!=NULL){
10 dfs(root->left,low,high);
11 if(root->val >= low && root->val <= high)
12 sum += root->val;
13 dfs(root->right,low,high);
14 }
15 }
16 };

LeetCode938. 二叉搜索树的范围和的更多相关文章

  1. [Swift]LeetCode938. 二叉搜索树的范围和 | Range Sum of BST

    Given the root node of a binary search tree, return the sum of values of all nodes with value betwee ...

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

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

  3. [数据结构]——二叉树(Binary Tree)、二叉搜索树(Binary Search Tree)及其衍生算法

    二叉树(Binary Tree)是最简单的树形数据结构,然而却十分精妙.其衍生出各种算法,以致于占据了数据结构的半壁江山.STL中大名顶顶的关联容器--集合(set).映射(map)便是使用二叉树实现 ...

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

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

  5. [LeetCode] Verify Preorder Sequence in Binary Search Tree 验证二叉搜索树的先序序列

    Given an array of numbers, verify whether it is the correct preorder traversal sequence of a binary ...

  6. [LeetCode] Lowest Common Ancestor of a Binary Search Tree 二叉搜索树的最小共同父节点

    Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BS ...

  7. [LeetCode] Binary Search Tree Iterator 二叉搜索树迭代器

    Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the ro ...

  8. [LeetCode] Convert Sorted List to Binary Search Tree 将有序链表转为二叉搜索树

    Given a singly linked list where elements are sorted in ascending order, convert it to a height bala ...

  9. [LeetCode] Convert Sorted Array to Binary Search Tree 将有序数组转为二叉搜索树

    Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 这道 ...

随机推荐

  1. idea 最好用的插件

    1.lombok 不用写get,set方法 2.MyBatisCodeHelperPro 3.Rainbow Brackets 彩虹括号 5.activate-power-mode 动感打字 7.Ba ...

  2. OkHttpClient调优案例

    OkHttpClient调优案例 作者:Grey 原文地址: 语雀 博客园 Github 实际案例 系统运行一段时间后,线程数量飙升,CPU持续居高不下 排查工具 https://fastthread ...

  3. js上 初识JavaScript

    1.JavaScript简介 **JavaScript ** 是什么?(重点) Js是一种专门为网页交互设计的客户端(浏览器端)的脚本语言: Js与html和css有相似之处,都在浏览器端解析: Js ...

  4. Java_day_01

    一.方法的定义 方法的定义在Java中可以使用多种方式,如果在定义的方法名前面加上 public static 关键字,即可直接在主方法(main)中调用 public class Method{ p ...

  5. angular8 大地老师学习笔记---第九课

    父组件:news组件 <app-header [title]="title" [msg]="msg" [run]='run' [home]='this'& ...

  6. C++libcurl的使用

    一.libcurl描述: 在curl的官方网站 **http://curl.haxx.se/download.html** 提供编译好libcurl包,  最后写一个demod工程,演示下libcur ...

  7. Arduino PROGMEM 从程序空间读取float值的方法

    方法: 使用avr-libc提供的宏定义: #define pgm_read_float_near(address_short) __LPM_float((uint16_t)(address_shor ...

  8. 最速下降法--MATLAB程序

    function x = fxsteep(f,e,a,b)x1 = a;x2 = b;Q = fxhesson(f,x1,x2);x0 = [x1,x2]';temp = [x0];fx1 = dif ...

  9. 基于frp的内网穿透实例1-通过SSH访问内网机器

    原文地址:https://wuter.cn/1804.html/ 老母鸡终于到了,作为一个能运行linux系统的四核1G硬件,它还是比较小巧的. FRP 全名:Fast Reverse Proxy.F ...

  10. oracle 19c dataguard aws ORA-03186报错

    环境说明 在亚马逊云AWS上面安装了一套oracle 19c dataguard,linux centos 7.7的操作系统,开始时同步正常,实时应用redolog,一会儿之后就不行了.报错如下: o ...