C just one line~~


  • 0
    B

    bool hasPathSum(struct TreeNode* root, int sum) {
    return !root?0:(!root->left&&!root->right?(sum==root->val?1:0):hasPathSum(root->left,sum-root->val)||hasPathSum(root->right,sum-root->val));
    }


Log in to reply
 

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