We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f6046d5 commit 0aa0f3dCopy full SHA for 0aa0f3d
bst_to_greater_tree.cpp
@@ -0,0 +1,23 @@
1
+/**
2
+ * Definition for a binary tree node.
3
+ * struct TreeNode {
4
+ * int val;
5
+ * TreeNode *left;
6
+ * TreeNode *right;
7
+ * TreeNode(int x) : val(x), left(NULL), right(NULL) {}
8
+ * };
9
+ */
10
+class Solution {
11
+public:
12
+
13
+ int sum = 0;
14
+ TreeNode* convertBST(TreeNode* root) {
15
+ if(root){
16
+ convertBST(root->right);
17
+ root->val += sum;
18
+ sum = root->val;
19
+ convertBST(root->left);
20
+ }
21
+ return root;
22
23
+};
0 commit comments