当前位置:网站首页>[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
边栏推荐
- Let‘s Encrypt
- 郑慧娟:基于统一大市场的数据资产应用场景与评估方法研究
- Website resources
- Is it safe to log in the securities account on the flush
- The size of STM32 stack
- ES6 adds -iterator traversal, for..Of loop
- Architecture design of multi live shopping mall
- 百度网盘+Chrom插件
- Process / thread synchronization mechanism
- Backgroundworker enables time-consuming operations without affecting interface response
猜你喜欢

阿里云SSL证书

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

Xiezhendong: Exploration and practice of digital transformation and upgrading of public transport industry

Okaleido tiger NFT is about to log in to binance NFT platform, and the future market continues to be optimistic

HLS编程入门

Go基础笔记_4_map

背景图和二维码合成

【1184. 公交站间的距离】

Implementation of cat and dog data set classification experiment based on tensorflow and keras convolutional neural network

Org.json Jsonexception: what about no value for value
随机推荐
IP first experiment hdcl encapsulates PPP, chap, mGRE
这个月 google的“AI具备意识”的事件的想法
Use and partial explanation of QDIR class
解决JSP无法使用session.getAttribute()
Browser cache
Icassp 2022 | KS transformer for multimodal emotion recognition
In pgplsql: = and=
Shardingsphere database sub database sub table introduction
基于Verilog HDL的数字秒表
【1184. 公交站间的距离】
激光雷达障碍物检测与追踪实战——cuda版欧式聚类
国信证券手机开户安全吗
ASP.NET Core 6.0 基于模型验证的数据验证
Zheng Huijuan: Research on application scenarios and evaluation methods of data assets based on the unified market
Go basic notes_ 4_ map
Burp's thinking from tracing to counteracting
Notes of Teacher Li Hongyi's 2020 in-depth learning series 7
Notes of Teacher Li Hongyi's 2020 in-depth learning series 2
ShardingSphere-数据库分库分表简介
QT6 with vs Code: compiling source code and basic configuration