Created
March 30, 2015 05:40
-
-
Save lamchau/f5ab7b6891d0cd0183f0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| var node = { | |
| value: -120, | |
| left: { | |
| value: -2120, | |
| left: { value: -20 }, | |
| right: { value: -30 } | |
| }, | |
| right: { | |
| value: -20, | |
| left: {value: 20 }, | |
| right: { value: 300 } | |
| } | |
| }; | |
| function getMax(x) { | |
| if (typeof x === 'undefined' || x === null) { | |
| return 0; | |
| } | |
| var left = getMax(x.left); | |
| var right = getMax(x.right); | |
| return x.value + Math.max(left, right); | |
| } | |
| console.log(getMax(node)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment