Skip to content

Instantly share code, notes, and snippets.

@Jwing28
Created October 17, 2017 02:00
Show Gist options
  • Save Jwing28/020d158d074f774daeaa448dbefe88ac to your computer and use it in GitHub Desktop.
Save Jwing28/020d158d074f774daeaa448dbefe88ac to your computer and use it in GitHub Desktop.
ConvertBST
//all nodes to the right and above current can be added to the value of the current node
//***How can I think about this? I try thinking about it visually and it's very slow to draw out the call stack
//is there a more effective way ? Often I get lost in the call stack.
var sum = 0;
var convertBST = function(root) {
if(root === null) return null;
convertBST(root.right);
root.val += sum;
sum = root.val;
convertBST(root.left);
console.log('x',root);
return root;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment