538. Convert BST to Greater Tree
// LeetCode 2020 easy #430nn// 538. Convert BST to Greater Treenn// Runtime: 60 ms, faster than 23.64% of C++ online sub
// LeetCode 2020 easy #430nn// 538. Convert BST to Greater Treenn// Runtime: 60 ms, faster than 23.64% of C++ online submissions for Convert BST to Greater Tree.n// Memory Usage: 27.3 MB, less than 14.29% of C++ online submissions for Convert BST to Greater Tree.nn/**n * Definition for a binary tree node.n * struct TreeNode {n * int val;n * TreeNode *left;n * TreeNode *right;n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}n * };n */nclass Solution {npublic:n TreeNode* convertBST(TreeNode* root) {n int val = 0;n convert(root, val);n return root;n }n n void convert(TreeNode* root, int& val) {n if (!root) return;n convert(root->right, val);n val += root->val;n root->val = val;n convert(root->left, val);n }n};n