/** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ funcfindMaxDepth(n *TreeNode,depth int)int{ dl,dr:=depth,depth if n.Left!=nil{ dl=findMaxDepth(n.Left,depth+1) } if n.Right!=nil{ dr=findMaxDepth(n.Right,depth+1) } if dl>dr{ return dl }else{ return dr } } funcmaxDepth(root *TreeNode)int { if root==nil{ return0 } return findMaxDepth(root,1) }