Leetcode 938. Range Sum of BST
import functools
# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
@functools.lru_cache()
class Solution(object):
def rangeSumBST(self, root, L, R):
"""
:type root: TreeNode
:type L: int
:type R: int
:rtype: int
"""
if not root:
return 0
return self.compare(root.val, L, R) + self.rangeSumBST(root.left, L, R) + self.rangeSumBST(root.right, L, R) def compare(self, val, L, R):
return val if L <= val <= R else 0
Leetcode 938. Range Sum of BST的更多相关文章
- LeetCode #938. Range Sum of BST 二叉搜索树的范围和
https://leetcode-cn.com/problems/range-sum-of-bst/ 二叉树中序遍历 二叉搜索树性质:一个节点大于所有其左子树的节点,小于其所有右子树的节点 /** * ...
- 【Leetcode_easy】938. Range Sum of BST
problem 938. Range Sum of BST 参考 1. Leetcode_easy_938. Range Sum of BST; 完
- 【LeetCode】938. Range Sum of BST 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 递归 日期 题目地址:https://leetcod ...
- 938. Range Sum of BST
Given the root node of a binary search tree, return the sum of values of all nodes with value betwee ...
- LeetCode--Jewels and Stones && Range Sum of BST (Easy)
771. Jewels and Stones (Easy)# You're given strings J representing the types of stones that are jewe ...
- [LeetCode] 303. Range Sum Query - Immutable 区域和检索 - 不可变
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...
- [LeetCode] 304. Range Sum Query 2D - Immutable 二维区域和检索 - 不可变
Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper lef ...
- [Leetcode Week16]Range Sum Query - Mutable
Range Sum Query - Mutable 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/range-sum-query-mutable/de ...
- [LeetCode] 307. Range Sum Query - Mutable 区域和检索 - 可变
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...
随机推荐
- dojo 官方翻译 dojo/aspect
官网地址:http://dojotoolkit.org/reference-guide/1.10/dojo/aspect.html after() 定义:after(target, methodNam ...
- Microsoft.VisualStudio.Web.PageInspector.Loader
未能加载文件或程序集"Microsoft.VisualStudio.Web.PageInspector.Loader, Version=1.0.0.0, Culture=neutral, P ...
- CentOS 7 安装各个桌面版本
http://unix.stackexchange.com/questions/181503/how-to-install-desktop-environments-on-centos-7 92dow ...
- JAVA基础补漏--多态
Fu obj = new ZI(); 访问成员变量规则 编译看左,运行看左. obj.num; 1.直接通过对象名访问成员变量:看等号左右是谁,优先用谁,没有则往上找. obj.getnum(); 2 ...
- idea发布到tomcat缺少jar
主要是需要自己添加jar到artifact,如果单个添加jar,则在右边栏右键选择 如果是把整个lib添加到toamcat发布,则选择下面的提示:
- HUE中Oozie执行Sqoop
Oozie执行Sqoop,传入参数(注意,在使用--query时,参数中一定不要带有空格,否则出错)1. 新建一个workflow 2. 拖入一个sqoop 3. sqoop抽取命令如下(建议先在命令 ...
- TrappingRainWater
问题描述: Given n non-negative integers representing an elevation map where the width of each bar is 1, ...
- DPDK-KERNEL NIC INTERFACE(内核NIC接口)
DPDK编程指南(翻译)( 二十一) 21.内核网络接口卡接口 DPDK Kernel NIC Interface(KNI)允许用户空间应用程序访问Linux *控制面. 使用DPDK KNI的好处是 ...
- 20165332 学习基础和C语言基础调查
学习基础和c语言基础调查 一.技能学习经验 从小学过很多东西,架子鼓.电子琴.街舞.吉他.书法.美术......爱好也有很多,乒乓球.篮球.唱歌......这么多项技能,要说那一项比大多数人好,还真的 ...
- javascript简单介绍总结(一)
DOM (Document Object Model)(文档对象模型)是用于访问 HTML 元素的正式 W3C 标准.在 HTML 中,JavaScript 语句向浏览器发出的命令.语句是用分号分隔: ...