Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //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;
- };
Add Comment
Please, Sign In to add comment