题解 | #二叉树的深度#

二叉树的深度

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
    }
}
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-01 11:47
点赞 评论 收藏
分享
05-09 13:22
门头沟学院 Java
点赞 评论 收藏
分享
陆续:不可思议 竟然没那就话 那就我来吧 :你是我在牛客见到的最美的女孩
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务