当前位置:网站首页>[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
边栏推荐
- Introduction to HLS programming
- Is it safe for Guosen Securities to open a mobile account
- Old Du servlet JSP
- Network Security Learning (I) virtual machine
- ASP. Net core 6.0 data validation based on model validation
- 必会面试题:1.浅拷贝和深拷贝_浅拷贝
- 新手哪个证券开户最好 开户最安全
- Org.json Jsonexception: what about no value for value
- QT | event system qevent
- Pointrender parsing
猜你喜欢

基于Verilog HDL的数字秒表

QT6 with vs Code: compiling source code and basic configuration

Burp's thinking from tracing to counteracting

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

Network Security Learning (V) DHCP

Li Kou 1184. Distance between bus stops

百度网盘+Chrom插件

价值驱动为商业BP转型提供核心动力——业务场景下的BP实现-商业BP分享

JS ------ Chapter II JS logic control

IP first experiment hdcl encapsulates PPP, chap, mGRE
随机推荐
Solve the problem that JSP cannot use session.getattribute()
GB、MB、KB分别是什么意思。大小分别是多少
Let‘s Encrypt
The size of STM32 stack
Okaleido tiger NFT即将登录Binance NFT平台,后市持续看好
Lidar obstacle detection and tracking: CUDA European clustering
解决JSP无法使用session.getAttribute()
Mandatory interview questions: 1. shallow copy and deep copy_ Deep copy
Learn AI through detectron2
基于FPGA的VGA显示
How to propose effective solutions for high-end products? (1 methodology + 2 cases + 1 List)
NVIDA-TensorRT部署(一)
把字符串转换成整数与不要二
Read and understand the advantages of the LAAS scheme of elephant swap
必会面试题:1.浅拷贝和深拷贝_深拷贝
Brainstorming -- using reduce method to reconstruct concat function
Baidu online disk +chrome plug-in
Piziheng embedded: the method of making source code into lib Library under MCU Xpress IDE and its difference with IAR and MDK
Effect evaluation of generative countermeasure network
Network Security Learning (IV) user and group management, NTFS