go + 递归

/**
  * 
  * @param root TreeNode类 
  * @param sum int整型 
  * @return bool布尔型
*/
func hasPathSum( root *TreeNode ,  sum int ) bool {
    // write code here
    if root == nil {
        return false
    }

    if root.Left == nil && root.Right == nil && root.Val == sum {
        return true
    }

    left, right := false, false
    if root.Left != nil {
        left = hasPathSum(root.Left, sum-root.Val)
    }
    if root.Right != nil {
        right = hasPathSum(root.Right, sum-root.Val)
    }

    return left || right
}