Go实现如下:

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, b int) int {
    if a > b {
        return a
    }
    return b
}