C# Solution


  • 0
    M
    public bool HasPathSum(TreeNode root, int sum) {
        if (root == null) return false; 
        if (root.left == null && root.right == null 
        && sum - root.val == 0) return true; 
        else return 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.