当前位置:网站首页>538. convert binary search tree to cumulative tree
538. convert binary search tree to cumulative tree
2022-06-11 06:29:00 【Saucey_ six】
subject :
Answer key :
Ideas : Reverse middle order traversal of binary search tree .
Code :
var convertBST = function (root) {
var start = 0;// Initially set to 0
var arr = [];
var p = root;
while (p || arr.length) {
while (p) {
arr.push(p)// Store the values of the right subtree
p = p.right// Traverse the right subtree of the right subtree
}
p = arr.pop(p)// Perform iterative accumulation
p.val += start;
start = p.val;
p = p.left// After traversing the right subtree, traverse the left subtree
}
return root
};
ps: the second day
边栏推荐
- 347. top k high frequency elements
- Graphsage paper reading
- QT socket setting connection timeout
- 572. 另一个树的子树
- Quantitative understanding (Quantitative deep revolutionary networks for effective information: a whitepaper)
- MATLAB realizes mean filtering and FPGA for comparison, and uses Modelsim waveform simulation
- Autojs, read one line, delete one line, and stop scripts other than your own
- 修复鼠标右键没有vscode快捷入口的问题
- 山东大学项目实训之examineListActivity
- Super explanation
猜你喜欢

Login and registration based on servlet, JSP and MySQL

Error reporting injection of SQL injection

Zvuldrill installation and customs clearance tutorial

Topic collection of FIFO minimum depth calculation

563. 二叉树的坡度

jenkins-不同风格的项目构建

Markdown + typora + picgo experimental report template attached

Sentinel annotation support - @sentinelresource usage details

FPGA面试题目笔记(二)——同步异步D触发器、静动态时序分析、分频设计、Retiming

Differences between FindIndex and indexof
随机推荐
Record the first data preprocessing process
通过两种方式手写一个消息队列
Matlab实现均值滤波与FPGA进行对比,并采用modelsim波形仿真
通过R语言且只用基础package来制作一个小游戏
The difference between call and apply and bind
Jenkins user rights management
On the social moral and ethical issues behind short videos (personal point of view, for reference only)
C语言大战“扫雷”
解决ffmpeg获取AAC音频文件duration不准
LeetCodeT526
学好C语言从关键字开始
MATLAB realizes mean filtering and FPGA for comparison, and uses Modelsim waveform simulation
Vulnhub's breach1.0 range exercise
FPGA设计——乒乓操作实现与modelsim仿真
UEFI查找PCI设备
[reading this article is enough!!! Easy to understand] confidence level understanding (95% confidence level and confidence interval)
Sqoop installation tutorial
Transfer Learning
break,continue有什么区别和用法?
FIFO最小深度计算的题目合集