Binary Search Tree to Greater Sum Tree LeetCode solution in Java

1
class Solution {
2
int sum = 0;
3

4
public TreeNode bstToGst(TreeNode root) {
5
if (root != null) {
6
bstToGst(root.right);
7
sum += root.val;
8
root.val = sum;
9
bstToGst(root.left);
10
}
11
return root;
12
}
13
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0