Skip to content

Instantly share code, notes, and snippets.

@cprodescu
Created September 18, 2016 16:43
Show Gist options
  • Save cprodescu/31be0b85e4f13de0c7ef5e9964ec26d4 to your computer and use it in GitHub Desktop.
Save cprodescu/31be0b85e4f13de0c7ef5e9964ec26d4 to your computer and use it in GitHub Desktop.
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