while (!queue.isEmpty()) { TreeNodecurNode= queue.poll(); inti= nodeMap.get(curNode);
res.computeIfAbsent(i, k -> newArrayList<>()).add(curNode.val); if (curNode.left != null) { queue.add(curNode.left); nodeMap.put(curNode.left, i - 1); }
if (curNode.right != null) { queue.add(curNode.right); nodeMap.put(curNode.right, i + 1); } }