DFS - 2 solutions - 9ms
Be careful with your shallow copy and deep copy in the currentPath parameter\n- As you see in my 1st solution: I use deep copy for every new currentPath, that w
**Be careful with your shallow copy and deep copy in the currentPath parameter**\n- As you see in my 1st solution: I use deep copy for every new currentPath, that would be a little bit slower, but you don\'t need to remove the last item you append to the recursion stack later (The line before the return statement)\n\t- Deep copy\n\t`newCurrentPath := make([]int, len(currentPath))`\n    `copy(newCurrentPath, currentPath)`\n\n- In 2nd solution, I use the shallow copy, basically, it means all the recursion use the same currentPath, that\'s why you need to remove item from recursion stack (The line before the return statement)\n\t- Shallow copy\n\tThen need to remove \n\t`currentPath = currentPath[:len(currentPath)-1]`\n\n```\nfunc pathSum(root *TreeNode, targetSum int) int {\n    return dfs(root, targetSum, []int{})\n}\n\nfunc dfs(root *TreeNode, target int, currentPath []int) int {\n    if root == nil {\n        return 0\n    }\n    \n    newCurrentPath := make([]int, len(currentPath))\n    copy(newCurrentPath, currentPath)\n    \n    newCurrentPath = append(newCurrentPath, root.Val)\n    pathCount, pathSum := 0, 0\n    \n    for i := len(newCurrentPath)-1; i >= 0; i-- {\n        pathSum += newCurrentPath[i]\n        \n        if pathSum == target {\n            pathCount++\n        }\n    }\n    \n    pathCount += dfs(root.Left, target, newCurrentPath)\n    pathCount += dfs(root.Right, target, newCurrentPath)\n    \n    return pathCount\n}\n```\n\n```\nfunc pathSum(root *TreeNode, targetSum int) int {\n    return dfs(root, targetSum, []int{})\n}\n\nfunc dfs(root *TreeNode, target int, currentPath []int) int {\n    if root == nil {\n        return 0\n    }\n    \n    currentPath = append(currentPath, root.Val)\n    pathCount, pathSum := 0, 0\n    \n    for i := len(currentPath)-1; i >= 0; i-- {\n        pathSum += currentPath[i]\n        \n        if pathSum == target {\n            pathCount++\n        }\n    }\n    \n    pathCount += dfs(root.Left, target, currentPath)\n    pathCount += dfs(root.Right, target, currentPath)\n    \n    currentPath = currentPath[:len(currentPath)-1]\n    \n    return pathCount\n}\n```
['Depth-First Search', 'Recursion', 'Go']