因为二叉搜索树的左子树<根<右子树的性质,按right-root-left的顺序遍历很容易求出累加和
1 int add = 0; 2 3 public TreeNode convertBST(TreeNode root) { 4 if (root == null) return root; 5 convertBST(root.right); 6 root.val += add; 7 add = root.val; 8 convertBST(root.left); 9 return root; 10 }