Path Sum

1     bool hasPathSum(TreeNode *root, int sum) {
2         // Start typing your C/C++ solution below
3         // DO NOT write int main() function
4         if(root == NULL)
5             return false;
6         if(sum == root->val && root->left==NULL && root->right==NULL)
7             return true;
8         return hasPathSum(root->left, sum-root->val)||hasPathSum(root->right, sum-root->val);
9     }

 

posted on 2013-09-30 20:15  waruzhi  阅读(152)  评论(0编辑  收藏  举报

导航