538.把二叉搜索树转换为累加树

convert-bst-to-greater-tree

题目描述
题目描述

代码

public class Solution {
	private int sum = 0;
	
	public TreeNode convertBST(TreeNode root){
		if(root!=null){
			//下面的遍历过程其实是把此方法返回值当void处理的
			convertBST(root.right);
			sum += root.val;
			root.val = sum;
			convertBST(root.left);
		}
		return root;
	}
}

性能表现
性能表现

发布了75 篇原创文章 · 获赞 0 · 访问量 1502

猜你喜欢

转载自blog.csdn.net/qq_34087914/article/details/104138369