LeetCode - 538 把二叉搜索树转换为累加树
作者:互联网
class Solution {
int sum = 0;
public TreeNode convertBST(TreeNode root) {
visitTree(root);
return root;
}
public void visitTree(TreeNode root){
if(root != null){
visitTree(root.right);
root.val = root.val + sum;
sum = root.val;
visitTree(root.left);
}
}
}
标签:visitTree,val,sum,二叉,public,TreeNode,root,LeetCode,538 来源: https://blog.csdn.net/qq_44822951/article/details/122594006