Solution in Golang


  • 0
    J
    func hasPathSum(root *TreeNode, sum int) bool {
        if (root == nil || (root.Left == nil && root.Right == nil && sum - root.Val !=0)) {
        		return false;
        	}
         return (root.Left == nil && root.Right == nil && sum - root.Val ==0) || hasPathSum(root.Left, sum - root.Val) || hasPathSum(root.Right, sum - root.Val);
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.