Golang | Leetcode Golang题解之第559题N叉树的最大深度-题解:

时间:2024-11-14 08:26:58
func maxDepth(root *Node) (ans int) {
    if root == nil {
        return
    }
    queue := []*Node{root}
    for len(queue) > 0 {
        q := queue
        queue = nil
        for _, node := range q {
            queue = append(queue, node.Children...)
        }
        ans++
    }
    return
}