C in 6ms


  • 0
    Z
    bool ishasPathSum(struct TreeNode* root, int sum,int count){
       if(!root) return false;
       if(root->val+count==sum&&!root->left&&!root->right) return true;
       return ishasPathSum(root->left,sum,root->val+count)||ishasPathSum(root->right,sum,root->val+count);}
    
    bool hasPathSum(struct TreeNode* root, int sum) {
       return ishasPathSum(root,sum,0);}

Log in to reply
 

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