可参考二叉树的最大深度。
function maxDepth(root: Node | null): number { if (root === null) return 0 if (root.children.length === 0) return 1 return Math.max(...root.children.map(child => maxDepth(child))) + 1 }