return currNode; }, new ListNode(arr[arr.length - 1])); }
functionbuildTree(arr) { if (!arr.length) returnnull; if (arr.length === 1) return parent; const parent = new TreeNode(arr[0]); const queue = [parent]; let index = 1;
while(queue.length) { const p = queue.shift(); if (p === null) { index++; continue; } if (index < arr.length) { p.left = arr[index] === null ? null : new TreeNode(arr[index]); queue.push(p.left); index++; } if (index < arr.length) { p.right = arr[index] === null ? null : new TreeNode(arr[index]); queue.push(p.right); index++; } } return parent; }