Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- bool f(TreeNode* root, int targetSum){
- if(root==NULL)return false;
- if(root->left==NULL && root->right==NULL && targetSum == root->val){
- return true;
- }
- if(f(root->left,targetSum-root->val)==true || f(root->right,targetSum-root->val)==true)return true;
- return false;
- }
- bool hasPathSum(TreeNode* root, int targetSum) {
- return f(root,targetSum);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement