MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / hasPathSum

Method hasPathSum

CPP/Trees/TargetSum.cpp:17–28  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15class Solution {
16public:
17 bool hasPathSum(TreeNode* root, int targetSum) {
18 if(root == NULL) {
19 return false;
20 }
21
22 targetSum = targetSum - root->val;
23 if(targetSum == 0 && root->left == NULL && root->right == NULL) {
24 return true;
25 }
26
27 return hasPathSum(root->left, targetSum) || hasPathSum(root->right, targetSum);
28 }
29};

Callers

nothing calls this directly

Calls 1

hasPathSumFunction · 0.85

Tested by

no test coverage detected