Skip to content

Commit a79c34d

Browse files
authored
538. Convert BST to Greater Tree
538. Convert BST to Greater Tree
1 parent 270fbd5 commit a79c34d

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

convertBST.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
private:
3+
int sum = 0;
4+
public:
5+
TreeNode* convertBST(TreeNode* root) {
6+
if(!root) return NULL;
7+
if(root->right) convertBST(root->right);
8+
root->val = (sum+=root->val);
9+
if(root->left) convertBST(root->left);
10+
return root;
11+
}
12+
};

0 commit comments

Comments
 (0)