当前位置:网站首页>[brother hero July training] day 20: search Binary Tree
[brother hero July training] day 20: search Binary Tree
2022-07-24 23:19:00 【If I were Wen Shuai】
Series articles
【 Brother hero training in July 】 The first 01 God : Array
【 Brother hero training in July 】 The first 02 God : character string
【 Brother hero training in July 】 The first 03 God : Sort
【 Brother hero training in July 】 The first 04 God : greedy
【 Brother hero training in July 】 The first 05 God : Double pointer
【 Brother hero training in July 】 The first 06 God : The sliding window
【 Brother hero training in July 】 The first 07 God : Hashtable
【 Brother hero training in July 】 The first 08 God : The prefix and
【 Brother hero training in July 】 The first 09 God : Two points search
【 Brother hero training in July 】 The first 10 God : An operation
【 Brother hero training in July 】 The first 11 God : matrix
【 Brother hero training in July 】 The first 12 God : Linked list
【 Brother hero training in July 】 The first 13 God : Double linked list
【 Brother hero training in July 】 The first 14 God : Stack
【 Brother hero training in July 】 The first 15 God : Depth-first search
【 Brother hero training in July 】 The first 16 God : queue
【 Brother hero training in July 】 The first 17 God : Breadth first search
【 Brother hero training in July 】 The first 18 God : Trees
【 Brother hero training in July 】 The first 19 God : Binary tree
【 Brother hero training in July 】 The first 20 God : Search binary trees
List of articles
One 、938. The range of binary search tree and
938. The range of binary search tree and
leetcode938 java
class Solution {
public int rangeSumBST(TreeNode root, int low, int high) {
if(root==null){
return 0;
}
int sum=0;
if(root.val<=high && root.val>=low){
sum+=root.val;
}
return sum+rangeSumBST(root.left,low,high)+rangeSumBST(root.right,low,high) ;
}
}
Two 、 The finger of the sword Offer II 054. Sum of all values greater than or equal to nodes
The finger of the sword Offer II 054. Sum of all values greater than or equal to nodes
leetcode The finger of the sword Offer II 054 java
class Solution {
public TreeNode convertBST(TreeNode root) {
int sum = 0;
TreeNode node = root;
while (node != null) {
if (node.right == null) {
sum += node.val;
node.val = sum;
node = node.left;
} else {
TreeNode succ = getSuccessor(node);
if (succ.left == null) {
succ.left = node;
node = node.right;
} else {
succ.left = null;
sum += node.val;
node.val = sum;
node = node.left;
}
}
}
return root;
}
public TreeNode getSuccessor(TreeNode node) {
TreeNode succ = node.right;
while (succ.left != null && succ.left != node) {
succ = succ.left;
}
return succ;
}
}
summary
边栏推荐
- 中金证券新客理财产品收益可以达到百分之六?开户怎么开?
- The size of STM32 stack
- Code coverage
- Three ways of shell debugging and debugging
- Can the income of CICC securities' new customer financial products reach 6%? How to open an account?
- Okaleido tiger NFT即将登录Binance NFT平台,后市持续看好
- 激光雷达障碍物检测与追踪实战——cuda版欧式聚类
- 认识复杂度和简单排序运算
- Notes of Teacher Li Hongyi's 2020 in-depth learning series lecture 1
- WPF uses pathgeometry to draw the hour hand and minute hand
猜你喜欢

QT6 with vs Code: compiling source code and basic configuration

Salesforce zero foundation learning (116) workflow - & gt; On flow

Background image and QR code synthesis
Browser cache

Go基础笔记_4_map

Network Security Learning (IV) user and group management, NTFS

"Yuan universe 2086" outsold "San ti" in one-day sales and won the champion of JD books' one-day science fiction list

Network Security Learning (I) virtual machine

Notes of Teacher Li Hongyi's 2020 in-depth learning series 6

基于FPGA的VGA显示
随机推荐
Backgroundworker enables time-consuming operations without affecting interface response
给生活加点惊喜,做创意生活的原型设计师丨编程挑战赛 x 选手分享
Baidu online disk +chrome plug-in
HLS编程入门
新手哪个证券开户最好 开户最安全
代码覆盖率
解决JSP无法使用session.getAttribute()
聊聊 Redis 是如何进行请求处理
中金证券新课理财产品的收益有百分之六吗?我想要开户理财
Is it safe to log in the securities account on the flush
ASP.NET Core 6.0 基于模型验证的数据验证
【云原生之kubernetes】kubernetes集群高级资源对象statefulesets
买收益百分之6的理财产品,需要开户吗?
yolov5
Network Security Learning (IV) user and group management, NTFS
关于板载继电器供电不足引起不能吸合的问题
ShardingSphere-数据库分库分表简介
Notes of Teacher Li Hongyi's 2020 in-depth learning series 9
The size of STM32 stack
痞子衡嵌入式:MCUXpresso IDE下将源码制作成Lib库方法及其与IAR,MDK差异