当前位置:网站首页>LeetCode 938. Range Sum of Binary Search Trees (Simple)
LeetCode 938. Range Sum of Binary Search Trees (Simple)
2022-08-10 05:55:00 【Shengxin Research Ape】
pyhton preorder traversal
# 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 = rightclass Solution:def rangeSumBST(self, root: Optional[TreeNode], low: int, high: int) -> int:self.count = 0if root==None:return Noneself.inorder(root,low,high)return self.countdef inorder(self,root,low,high):p = rootif p==None:returnif(p.val>=low and p.val<=high):self.count +=p.valself.inorder(p.left,low,high)self.inorder(p.right,low,high)
边栏推荐
猜你喜欢
随机推荐
R语言聚类分析——代码解析
MySql 约束
PyTorch 之 可视化网络架构
Chain Reading|The latest and most complete digital collection sales calendar-08.02
Linux database Oracle client installation, used for shell scripts to connect to the database with sqlplus
The latest and most complete digital collection sales calendar-07.27
The latest and most complete digital collection sales calendar-07.26
cesium add point, move point
[Notes] Collection Framework System Collection
探索性数据分析EDA
Timer (setInterval) on and off
事务、存储引擎
深度学习TensorFlow入门环境配置
LeetCode 292.Nim 游戏(简单)
The submenu of the el-cascader cascade selector is double-clicked to display the selected content
MySql constraints
链读好文:热加密存储与冷加密存储有什么区别?
Common class BigDecimal
细说MySql索引原理
Copy large files with crontab