题解 | #二叉树的最大深度#
二叉树的最大深度
https://www.nowcoder.com/practice/8a2b2bf6c19b4f23a9bdb9b233eefa73
package main import . "nc_tools" /* * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ /** * * @param root TreeNode类 * @return int整型 */ func maxDepth( root *TreeNode ) int { // write code here if root == nil{ return 0 } left := maxDepth(root.Left) right := maxDepth(root.Right) return max(left, right) + 1 } func max(a int ,b int) int{ if a<b{ return b }else{ return a } }