```
class Solution {
public:
int pathSum(TreeNode* root, int sum, bool is_count = false) {
if (!root) return 0;
if (is_count) sum -= root->val;
return (is_count ? sum == 0 : pathSum(root, sum, true)) + pathSum(root->left, sum, is_count) + pathSum(root->right, sum, is_count);
}
};
```