Easy Java Solution || 100% Faster || 91% Memory
\nclass Solution {\n    int sum = 0;\n    public int pathSum(TreeNode root, int targetSum) {\n      if (root == null)\n        return 0;\n      Map<Long, Intege
```\nclass Solution {\n    int sum = 0;\n    public int pathSum(TreeNode root, int targetSum) {\n      if (root == null)\n        return 0;\n      Map<Long, Integer> map = new HashMap<>();\n      map.put((long)0, 1);\n      \n      dfs(root, targetSum, map, (long)0);\n      \n      return sum; \n  }\n  \n    public void dfs(TreeNode root, int target, Map<Long, Integer> map, long current) {\n      \n      if (root == null)\n        return; \n      \n      current = current + root.val;\n      \n      if (map.containsKey(current - target)) {\n        sum += map.get(current - target);\n      }\n      \n      map.put(current, map.getOrDefault(current, 0) + 1);\n      \n      if (root.left != null)\n        dfs(root.left, target, map, current);\n      \n      if (root.right != null)\n        dfs(root.right, target, map, current); \n        \n        map.put(current, map.get(current) - 1);\n      \n    }\n}\n```
['Depth-First Search', 'Recursion', 'Prefix Sum', 'Java']