Typescript | Javascript | WIth comments | DFS
\nfunction pathSum(root: TreeNode | null, targetSum: number): number {\n  return dfs(root, targetSum, []);\n};\n\nfunction dfs(root: TreeNode | null, targetSum:
```\nfunction pathSum(root: TreeNode | null, targetSum: number): number {\n  return dfs(root, targetSum, []);\n};\n\nfunction dfs(root: TreeNode | null, targetSum: number, currentPath: number[]) {\n  if(!root) return 0;\n  \n  // add current node to path\n  currentPath.push(root.val);\n  let count = 0;\n  let sum = 0;\n  \n  // calculate sum for current path\n  // we start from last added element\n  // to avoid calculating same path twice\n  for(let i = currentPath.length - 1 ; i >= 0 ; i--){\n    sum = sum + currentPath[i];\n    if(sum === targetSum)\n      count++;\n  }\n  \n  // continue for left and right sub trees\n  count += dfs(root.left, targetSum, currentPath);\n  count += dfs(root.right, targetSum, currentPath);\n  \n  // remove the current node from current path \n  // because we want to traverse a different path that \n  // doesn\'t have this node in it\n  currentPath.pop();\n  return count;\n}\n```
['Depth-First Search', 'TypeScript', 'JavaScript']