parent
64d5bddff4
commit
2ca96d0177
@ -1,38 +0,0 @@
|
|||||||
const tree = {
|
|
||||||
left:{
|
|
||||||
left: {
|
|
||||||
left:{
|
|
||||||
left: {},
|
|
||||||
right: {}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
right: {}
|
|
||||||
},
|
|
||||||
right: {
|
|
||||||
left: {},
|
|
||||||
right: {
|
|
||||||
left: {},
|
|
||||||
right: {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const paths = [];
|
|
||||||
let currPath = '';
|
|
||||||
const traverse = (node)=>{
|
|
||||||
if(node.left === undefined && node.right === undefined){
|
|
||||||
paths.push(currPath)
|
|
||||||
}
|
|
||||||
if(node.left){
|
|
||||||
currPath += 'l';
|
|
||||||
traverse(node.left)
|
|
||||||
}
|
|
||||||
if(node.right){
|
|
||||||
currPath += 'r';
|
|
||||||
traverse(node.right)
|
|
||||||
}
|
|
||||||
currPath = currPath.substring(0, currPath.length-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
traverse(tree)
|
|
||||||
console.log(paths);
|
|
||||||
Loading…
Reference in new issue