title: 112.path sum leetcode wong answer for two test cases
body: <p><a href="https://leetcode.com/problems/path-sum/" rel="nofollow noreferrer">problem</a> My code fails for the following test case. I don't understand why. Can you tell me where I went wrong? My code passes (114/116) test cases. I'm doing DFS and checking whether <code>currSum==targetSum</code> and if it satisfies this condition and it's also a leaf node I'm setting global variable ```flag=true``.</p>
  <pre><code>[1,-2,-3,1,3,-2,null,-1]
  -1
  </code></pre>
  <pre><code>/**
   * Definition for a binary tree node.
   * struct TreeNode {
   *     int val;
   *     TreeNode *left;
   *     TreeNode *right;
   *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
   *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
   *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
   * };
   */
  class Solution {
  public:
      bool flag=false;
      void dfs(TreeNode *root, int currSum, int targetSum){
          if(root==NULL) return ;
          // cout&lt;&lt;currSum&lt;&lt;&quot; &quot;;
          currSum+=root-&gt;val;
          cout&lt;&lt;currSum&lt;&lt;&quot; &quot;;
          if(currSum == targetSum) {
              if(root-&gt;left==NULL &amp;&amp; root-&gt;right==NULL) flag=true;
              return;
          }
          
          // else if(abs(currSum)&gt;abs(targetSum)) return;
          dfs(root-&gt;left,currSum,targetSum);
          dfs(root-&gt;right,currSum,targetSum);
      }
      
      bool hasPathSum(TreeNode* root, int targetSum) {
          int currSum=0;
          dfs(root,currSum,targetSum);
          return flag;        
      }
  };
  </code></pre>