Created
October 17, 2017 02:00
-
-
Save Jwing28/020d158d074f774daeaa448dbefe88ac to your computer and use it in GitHub Desktop.
ConvertBST
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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