Skip to content

Instantly share code, notes, and snippets.

@Kishy-nivas
Created June 20, 2018 14:48
Show Gist options
  • Save Kishy-nivas/c291174c55393caff5bf888e2078b5e7 to your computer and use it in GitHub Desktop.
Save Kishy-nivas/c291174c55393caff5bf888e2078b5e7 to your computer and use it in GitHub Desktop.
greater_tree.cpp
class Solution {
public:
int sum =0;
TreeNode* convertBST(TreeNode* root) {
if(root == nullptr)
return nullptr;
convertBST(root->right);
sum += root->val;
root->val = sum ;
convertBST(root->left);
return root;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment