0 class Solution {
11 public:
12     bool dfs(TreeNode *node, int sum, int curSum)
13     {
14         if (node == NULL)
15             return false;
16         
17         if (node->left == NULL && node->right == NULL)
18             return curSum + node->val == sum;
19                
20         return dfs(node->left, sum, curSum + node->val) || dfs(node->right, sum, curSum + node->val);
21     }
22     
23     bool hasPathSum(TreeNode *root, int sum) {
24         // Start typing your C/C++ solution below
25         // DO NOT write int main() function
26         return dfs(root, sum, 0);
27     }
28 };原文:http://www.cnblogs.com/qiaozhoulin/p/4509905.html