Guest User

Untitled

a guest
Oct 17th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. //all nodes to the right and above current can be added to the value of the current node
  2. //***How can I think about this? I try thinking about it visually and it's very slow to draw out the call stack
  3. //is there a more effective way ? Often I get lost in the call stack.
  4.  
  5. var sum = 0;
  6. var convertBST = function(root) {
  7.  
  8. if(root === null) return null;
  9. convertBST(root.right);
  10. root.val += sum;
  11. sum = root.val;
  12. convertBST(root.left);
  13. console.log('x',root);
  14. return root;
  15. };
Add Comment
Please, Sign In to add comment