Skip to content

Commit 5fb6677

Browse files
committed
Solution as on 20-04-2022 08:50 pm
1 parent b0c48cf commit 5fb6677

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// 538.✅ Convert BST to Greater Tree
2+
3+
class Solution
4+
{
5+
public:
6+
void helper(TreeNode *root, int &total)
7+
{
8+
if (!root)
9+
return;
10+
helper(root->right, total);
11+
total += root->val;
12+
root->val = total;
13+
helper(root->left, total);
14+
}
15+
16+
TreeNode *convertBST(TreeNode *root)
17+
{
18+
int total = 0;
19+
helper(root, total);
20+
return root;
21+
}
22+
};

0 commit comments

Comments
 (0)