题目

 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. ORA-01578: ORACLE data block corrupted (file # 3, block # 1675)

    警告日志中发现如下报错信息: ORA-01578: ORACLE data block corrupted (file # 3, block # 1675)ORA-01110: data file 3 ...

  2. 接口测试工具 Jmeter使用笔记(一:编写一个http请求)

    记录学习过程 一.安装Jmeter 1.JAVA环境 JDK下载地址http://java.sun.com/javase/downloads/index.jsp 配置系统变量: (1)JAVA_HOM ...

  3. 01-flask-helloWorld

    代码 from flask import Flask # 创建Flask对象 app = Flask(__name__) # 定义路由 @app.route('/') def index(): # 函 ...

  4. 题解 P1579 【哥德巴赫猜想(升级版)】

    蒟蒻AC代码,讲解请看题解中. 1 #include<bits/stdc++.h> 2 #include<iostream> 3 #include<cmath> / ...

  5. Spark性能调优篇八之shuffle调优

    1 task的内存缓冲调节参数 2 reduce端聚合内存占比 spark.shuffle.file.buffer                     map task的内存缓冲调节参数,默认是3 ...

  6. 第三章 Nacos Discovery--服务治理

    之前我讲过 Nacos文章 的内容,想要深入了解的 朋友的话,可以去看看 ,我们继续承接上篇讲下去 --> 第二章 : 微服务环境搭建 3.1 服务治理介绍 先来思考一个问题 通过上一章的操作, ...

  7. Centos7__Scrapy + Scrapy_redis 用Docker 实现分布式爬虫

    原理:其实就是用到redis的优点及特性,好处自己查--- 1,scrapy 分布式爬虫配置: settings.py BOT_NAME = 'first' SPIDER_MODULES = ['fi ...

  8. 仙剑4CPK加密解密算法(转)

    // RSTEncDec.h: interface for the CRSTEncDec class. // ///////////////////////////////////////////// ...

  9. Kafka数据每5分钟同步到Hive

    1.概述 最近有同学留言咨询Kafka数据落地到Hive的一些问题,今天笔者将为大家来介绍一种除Flink流批一体以外的方式(流批一体下次再单独写一篇给大家分享). 2.内容 首先,我们简单来描述一下 ...

  10. 异步技巧之CompletableFuture

    摘自--https://juejin.im/post/5b4622df5188251ac9766f47 异步技巧之CompletableFuture 1.Future接口 1.1 什么是Future? ...