/* function TreeNode(x) { this.val = x; this.left = null; this.right = null; } */ functionPrint (pRoot) { // write code here if (!pRoot) return [] let result = [] let lstack = [] let rstack = [] lstack.push(pRoot) while (lstack.length || rstack.length) { let line = [] if (lstack.length) { while (lstack.length) { let item = lstack.pop() line.push(item.val) if (item.left) rstack.push(item.left) if (item.right) rstack.push(item.right) } } else { while (rstack.length) { let item = rstack.pop() line.push(item.val) if (item.right) lstack.push(item.right) if (item.left) lstack.push(item.left) } } result.push(line) } return result }