当前位置:网站首页>LeetCode 938.二叉搜索树的范围和(简单)
LeetCode 938.二叉搜索树的范围和(简单)
2022-08-10 05:32:00 【生信研究猿】
pyhton 前序遍历
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def rangeSumBST(self, root: Optional[TreeNode], low: int, high: int) -> int:
self.count = 0
if root==None:
return None
self.inorder(root,low,high)
return self.count
def inorder(self,root,low,high):
p = root
if p==None:
return
if(p.val>=low and p.val<=high):
self.count +=p.val
self.inorder(p.left,low,high)
self.inorder(p.right,low,high)
边栏推荐
猜你喜欢
链读推荐:从瓷砖到生成式 NFT
Chain Reading Good Article: Jeff Garzik Launches Web3 Production Company
Chain Reading Recommendation: From Tiles to Generative NFTs
链读 | 最新最全的数字藏品发售日历-07.28
链表API设计
卷积神经网络(CNN)实现mnist手写数字识别
【List练习】遍历集合并且按照价格从低到高排序,
Chain Reading|The latest and most complete digital collection sales calendar-08.02
图片批量添加水印批量加背景缩放批量合并工具picUnionV4.0
generic notes()()()
随机推荐
定时器(setInterval)的开启与关闭
集合 Map
树结构——2-3树图解
去中心化和p2p网络以及中心化为核心的传统通信
事务、存储引擎
链读好文:Jeff Garzik 推出 Web3 制作公司
力扣——省份数量
transaction, storage engine
MySQL中MyISAM为什么比InnoDB查询快
pytorch-09.多分类问题
MySql 约束
数据库 笔记 创建数据库、表 备份
Chain Reading|The latest and most complete digital collection sales calendar-08.02
利用 crontab 拷贝大文件
Chained Picks: Starbucks looks at digital collectibles and better engages customers
ACID四种特性
我不喜欢我的代码
复杂的“元宇宙”,为您解读,链读APP即将上线!
力扣——情侣牵手
十年磨一剑!数字藏品行情软件,链读APP正式开放内测!