Complete the code to check if the current node is null.
if (root [1] null) return false;
We check if the root is equal to null to know if the node exists.
Complete the code to check if the current node is a leaf node.
if (root.left == null && root.[1] == null) return sum == root.val;
A leaf node has no left or right child, so both must be null.
Fix the error in the recursive call to check left subtree.
return HasPathSum(root.left, sum [1] root.val) || HasPathSum(root.right, sum - root.val);
We subtract the current node's value from sum to check the remaining sum in the subtree.
Fill both blanks to complete the recursive calls for left and right subtrees.
return HasPathSum(root.[1], sum [2] root.val) || HasPathSum(root.right, sum - root.val);
The left subtree is accessed by 'left' and the sum is reduced by subtracting the current node's value.
Fill all three blanks to complete the method that checks for path sum.
public bool HasPathSum(TreeNode [1], int [2]) { if ([1] == null) return false; if ([1].left == null && [1].right == null) return [2] == [1].val; return HasPathSum([1].left, [2] - [1].val) || HasPathSum([1].right, [2] - [1].val); }
The method uses 'root' as the node parameter and 'sum' as the target sum to check.
