From 3b009d6a60e10a0f258d1acac0e3dda2d2acc34e Mon Sep 17 00:00:00 2001 From: Shrivali Dutt <149003676+shrivalidutt@users.noreply.github.com> Date: Thu, 17 Oct 2024 01:07:37 +0530 Subject: [PATCH] Update Pathsum.cpp The NULL check at the beginning of hasPathSum() was removed because the checkPathSum() function already handles the NULL case. The and was replaced with && in if (root->left == NULL && root->right == NULL) to ensure correct C++ syntax. --- Leetcode/Pathsum.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Leetcode/Pathsum.cpp b/Leetcode/Pathsum.cpp index dbc50a4..76b3bfc 100644 --- a/Leetcode/Pathsum.cpp +++ b/Leetcode/Pathsum.cpp @@ -5,15 +5,12 @@ class Solution { return false; } pres_sum+=root->val; - if(root->left == NULL and root->right == NULL){ + if(root->left == NULL && root->right == NULL){ return pres_sum == targetSum; } return havingPathSum(root->left,targetSum,pres_sum) || havingPathSum(root->right,targetSum,pres_sum); } bool hasPathSum(TreeNode* root, int targetSum) { - if(root == NULL){ - return false; - } return havingPathSum(root,targetSum,0); }