Skip to content

Latest commit

 

History

History
22 lines (21 loc) · 421 Bytes

添加559.n叉树的最大深度Go版本.md

File metadata and controls

22 lines (21 loc) · 421 Bytes
func maxDepth(root *Node) int {
    if root == nil {
        return 0
    }
    q := list.New()
    q.PushBack(root)
    depth := 0
    for q.Len() > 0 {
        n := q.Len()
        for i := 0; i < n; i++ {
            node := q.Remove(q.Front()).(*Node)
            for j := range node.Children {
                q.PushBack(node.Children[j])
            }
        }
        depth++
    }
    return depth 
}