Created
September 18, 2016 16:43
-
-
Save cprodescu/31be0b85e4f13de0c7ef5e9964ec26d4 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
acc = null; | |
savedPaths = []; | |
function dfs(node) { | |
if (acc != null) { | |
acc = acc + node.weight; | |
} | |
if (isLeaf(node)) { | |
if (acc != null) { | |
savedPaths.push(acc); | |
} | |
acc = 0; | |
} else { | |
for (child in node.children) { | |
dfs(child); | |
} | |
} | |
if (acc != null) { | |
acc = acc + node.weight; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment