C++ 5 Line Body Code DFS Solution
For tree structure problems. recursion is usually intuitive and easy to write. lol\n\nclass Solution {\npublic:\n    int pathSum(TreeNode* root, int sum) {\n   
For tree structure problems. recursion is usually intuitive and easy to write. lol\n```\nclass Solution {\npublic:\n    int pathSum(TreeNode* root, int sum) {\n        if(!root) return 0;\n        return sumUp(root, 0, sum) + pathSum(root->left, sum) + pathSum(root->right, sum);\n    }\nprivate:\n    int sumUp(TreeNode* root, int pre, int& sum){\n        if(!root) return 0;\n        int current = pre + root->val;\n        return (current == sum) + sumUp(root->left, current, sum) + sumUp(root->right, current, sum);\n    }\n};\n```
[]