Javascript Solution. Beats 99%
Recursive\n\nRuntime: 63 ms, faster than 97.13% of JavaScript online submissions for Binary Tree Level Order Traversal.\nMemory Usage: 44.1 MB, less than 77.04%
**Recursive**\n\nRuntime: 63 ms, faster than 97.13% of JavaScript online submissions for Binary Tree Level Order Traversal.\nMemory Usage: 44.1 MB, less than 77.04% of JavaScript online submissions for Binary Tree Level Order Traversal.\n\n```\n/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n *     this.val = (val===undefined ? 0 : val)\n *     this.left = (left===undefined ? null : left)\n *     this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number[][]}\n */\nvar levelOrder = function(root) {\n    const results = []\n    \n    if (!root) return results\n    \n    const dfs = (node, level) => {\n        results[level] = [...(results[level] || []), node.val]\n        if (node.left) dfs(node.left, level + 1)\n        if (node.right) dfs(node.right, level + 1)\n    }\n    \n    dfs(root, 0)\n    \n    return results\n};\n```\n\n**Iterative**\n\nRuntime: 44 ms, faster than 99.51% of JavaScript online submissions for Binary Tree Level Order Traversal.\nMemory Usage: 34.9 MB, less than 64.71% of JavaScript online submissions for Binary Tree Level Order Traversal.\n\n```\n/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n *     this.val = val;\n *     this.left = this.right = null;\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number[][]}\n */\nvar levelOrder = function(root) {\n    if (!root) return []\n    const arr = [root], result = []\n    while (arr.length) {\n        const size = arr.length, values = []\n        for (let i = 0; i < size; i++) {\n            const node = arr.shift()\n            values.push(node.val)\n            if (node.left) arr.push(node.left) \n            if (node.right) arr.push(node.right) \n        }\n        result.push(values)\n    }\n    return result\n};\n```
[]