- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_1038.java
23 lines (20 loc) · 686 Bytes
/
_1038.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
packagecom.fishercoder.solutions.secondthousand;
importcom.fishercoder.common.classes.TreeNode;
publicclass_1038 {
publicstaticclassSolution1 {
/*
* credit: https://leetcode.com/problems/binary-search-tree-to-greater-sum-tree/discuss/286725/JavaC%2B%2BPython-Revered-Inorder-Traversal
*/
intgreaterSum = 0;
publicTreeNodebstToGst(TreeNoderoot) {
if (root.right != null) {
bstToGst(root.right);
}
greaterSum = root.val = greaterSum + root.val;
if (root.left != null) {
bstToGst(root.left);
}
returnroot;
}
}
}