Skip to content

Commit

Permalink
538
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangshanmeta committed Dec 13, 2024
1 parent 20e2219 commit 4c59095
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/0538.convert-bst-to-greater-tree.538/solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode() {}
* TreeNode(int val) { this.val = val; }
* TreeNode(int val, TreeNode left, TreeNode right) {
* this.val = val;
* this.left = left;
* this.right = right;
* }
* }
*/
class Solution {
int sum = 0;
public TreeNode convertBST(TreeNode root) {
if(root == null){
return null;
}
convertBST(root.right);

sum += root.val;;
root.val = sum;

convertBST(root.left);

return root;
}
}

0 comments on commit 4c59095

Please sign in to comment.