You are viewing a single comment's thread. Return to all comments →
Very Simple Javascript Recursive Solution
const resp = []
function helperFunc(root) { if(!root) return; resp.push(root.data) helperFunc(root.left); helperFunc(root.right); }
function preOrder(root) { helperFunc(root); console.log(resp.join(' ')); }
Seems like cookies are disabled on this browser, please enable them to open this website
I agree to HackerRank's Terms of Service and Privacy Policy.
Tree: Preorder Traversal
You are viewing a single comment's thread. Return to all comments →
Very Simple Javascript Recursive Solution
const resp = []
function helperFunc(root) { if(!root) return; resp.push(root.data) helperFunc(root.left); helperFunc(root.right); }
function preOrder(root) { helperFunc(root); console.log(resp.join(' ')); }