C# Solution


  • 0
        public bool HasPathSum(TreeNode root, int sum) {
            if (root == null || (root.right == null && root.left == null && root.val != sum))
                return false;
            else if (root.right == null && root.left == null && root.val == sum)
                return true;
            
            return HasPathSum(root.right, sum - root.val) || HasPathSum(root.left, sum - root.val);
        }

Log in to reply
 

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