当前位置:网站首页>538.把二叉搜索树转换成累加树
538.把二叉搜索树转换成累加树
2022-06-11 06:23:00 【Saucey_6】
题目:
题解:
思路:二叉搜索树的反向中序遍历。
代码:
var convertBST = function (root) {
var start = 0;//初始设为0
var arr = [];
var p = root;
while (p || arr.length) {
while (p) {
arr.push(p)//将右子树的值存储
p = p.right//遍历右子树的右子树
}
p = arr.pop(p)//进行迭代累加
p.val += start;
start = p.val;
p = p.left//右子树遍历完毕进行左子树遍历
}
return root
};
ps:第二天
边栏推荐
- Docker安装Mysql、Redis
- ERROR 1215 (HY000): Cannot add foreign key constraint
- Continuous update of ansible learning
- MATLAB realizes mean filtering and FPGA for comparison, and uses Modelsim waveform simulation
- [must see for game development] 3-step configuration p4ignore + wonderful Q & A analysis (reprinted from user articles)
- Why is it that the live video of the devices connected to easygbs suddenly cannot be played? Insufficient database read / write
- Box model
- Notes sur les questions d'entrevue de la FPGA (IV) - - détecteur de séquence, Code gris dans le domaine de l'horloge croisée, opération de ping - pong, réduction de la perte statique et dynamique, err
- Completabilefuture asynchronous task choreography usage and explanation
- Sqli-libs post injection question 11-17 actual combat
猜你喜欢

Moteur de modèle de moteur thymeleaf

Do you know the functions of getbit and setbit in redis?

Sqli-libs post injection question 11-17 actual combat

The artistic director and production designer of Disney's Mandalorian revealed the virtual scene production behind it

Squid agent

Zvuldrill installation and customs clearance tutorial

MMEditing中超分模型训练与测试

Error reporting injection of SQL injection

jenkins-用户权限管理

MATLAB realizes mean filtering and FPGA for comparison, and uses Modelsim waveform simulation
随机推荐
Servlet
Shuffleerror:error in shuffle in fetcher solution
Warmly celebrate that yeyanxiu, senior consultant of Longzhi, won the title of "atlassian Certified Expert"
FPGA面试题目笔记(四)—— 序列检测器、跨时钟域中的格雷码、乒乓操作、降低静动态损耗、定点化无损误差、恢复时间和移除时间
The difference between call and apply and bind
修复鼠标右键没有vscode快捷入口的问题
Goodbye 2021 Hello 2022
不同VLAN间的通信
Use of constructors
ijkPlayer中的错误码
个人常用软件及浏览器插件分享
021-MongoDB数据库从入门到放弃
FPGA设计中提高工作频率及降低功耗题目合集
Detailed installation instructions for MySQL
PHP laravel8 send email
Teach you to write word formula
Jenkins voucher management
Multimedia框架解析之MediaExtractor源码分析(一)
关于SIoU的原理和代码实现(回顾IoU、GIoU、DIoU、CIoU)
C语言大战“扫雷”