go解题答案
- 思路概括:dfs
- 思路核心:
1、nil节点返回0,本层高度是1+子节点func maxDepth( root *TreeNode ) int { // write code here if root==nil { return 0 } left:=1+maxDepth(root.Left) right:=1+maxDepth(root.Right) if left>right{ return left } return right }
如果有帮助请点个赞哦, 更多文章请看我的博客
题主背景
- 从业8年——超级内卷500Q技术经理——目前专注go和微服务架构