var convertBST = function(root) {
let num = 0;
function bst(root){
if (root != null) {
//遍历右子树
bst(root.right);
//遍历顶点
root.val = root.val + num;
num = root.val;
//遍历左子树
bst(root.left);
}
}
bst(root);
return root;
};
力扣第538题-把二叉搜索树转换为累加树
- 本文链接:http://gulinga.github.io/2022/11/18/arithmetic/LeetCode%E7%83%AD%E9%A2%98HOT100/538/
- 版权声明:本博客所有文章除特别声明外,均默认采用 许可协议。