Root to leaf path with given sum in binary tree For a given binary tree and a sum, I have written the following function to check whether there is a root to leaf path in that tree with the given sum.

/* 
//A binary tree node
struct Node
{
    int data;
    struct Node* left, * right;
}; 
*/

bool hasPathSum(Node *node, int sum)
{
    if(!node)
        return sum==0;

    return ( hasPathSum(node-&gt;left,  sum-node-&gt;data) || 
             hasPathSum(node-&gt;right, sum-node-&gt;data) );
}


Are there any edge cases in which the code will break? Also, do comment on the code style.
Give your operators some breathing space.

    if (!node) {
        return sum == 0;
    }

    return hasPathSum(node-&gt;left,  sum - node-&gt;data) || 
           hasPathSum(node-&gt;right, sum - node-&gt;data);


Note that return expression needs no parenthesis.
sum - node-&gt;data seems more natural to be expressed once:

    sum -= node-&gt;data;
    return hasPathSum(node-&gt;left,  sum) || 
           hasPathSum(node-&gt;right, sum);

I see no edge cases except possible overflows.