leetcode-559. N 叉树的最大深度
dfs
/**
* Definition for a Node.
* type Node struct {
* Val int
* Children []*Node
* }
*/
func maxDepth(root *Node) int {
if root == nil {
return 0
}
maxSubDepth := 0
for _, v := range root.Children {
if v == nil {
continue
}
subDepth := maxDepth(v)
if subDepth > maxSubDepth {
maxSubDepth = subDepth
}
}
return maxSubDepth + 1
}
本文来自博客园,作者:吴丹阳-V,转载请注明原文链接:https://www.cnblogs.com/wudanyang/p/17017208.html