Untitled

mail@pastecode.io avatar
unknown
c_cpp
3 years ago
574 B
2
Indexable
Never
 bool hasPathSum(TreeNode* root, int targetSum) {
        if(root == NULL)    return false;
        if(root->val == targetSum){
            if(root->left == NULL && root->right == NULL)
                return true;
        }
        
        bool left, right;
        
     
            left = hasPathSum(root->left, targetSum - root->val);
            right= hasPathSum(root->right, targetSum - root->val);
            
            if(left == true)    return true;
            if(right == true)   return true;
        
        return false;
        
    }