题解 | #二叉树的深度#
二叉树的深度
http://www.nowcoder.com/practice/435fb86331474282a3499955f0a41e8b
package main
import . "nc_tools"
type TreeNode struct {
Val int
Left *TreeNode
Rigth *TreeNode
}
func TreeDepth(root *TreeNode ) int {
if root == nil {
return 0
}
leftDepth := TreeDepth(root.Left)
rightDepth := TreeDepth(root.Right)
if leftDepth > rightDepth {
return leftDepth + 1
}else {
return rightDepth + 1
}
}