/**
* Definition for a binary tree node.
* function TreeNode(val) {
* this.val = val;
* this.left = this.right = null;
* }
*/
/**
* @param {TreeNode} root
* @return {number[][]}
*/
var levelOrder = function(root) {
const arr = [];
const flat = (node, height) => {
if (!node) return;
arr[height] = arr[height] || [];
arr[height].push(node.val);
height++;
flat(node.left, height);
flat(node.right, height);
}
flat(root, 0);
// console.log(arr);
return arr;
};