/* * function TreeNode(x) { * this.val = x; * this.left = null; * this.right = null; * } */ /** * * @param root TreeNode类 * @return int整型二维数组 */ function levelOrder( root ) { // write code here if(!root) return []; let queue = [root]; let res = []; while(queue.length){ let temp = [] let queueLength = queue.length; while(queueLength) { let node = queue.shift(); node.left && queue.push(node.left); node.right && queue.push(node.right) queueLength--; temp.push(node.val); } res.push(temp); } return res } module.exports = { levelOrder : levelOrder };