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 var dfs func(root *TreeNode) int dfs = func(root *TreeNode) int { if root == nil { return 0 } return max(dfs(root.Left), dfs(root.Right)) + 1 } return dfs(root) } func max (a, b int) int { if a > b { return a } return b }