package leetcode
import (
"github.com/halfrost/LeetCode-Go/structures"
)
type TreeNode = structures.TreeNode
func findTarget(root *TreeNode, k int) bool {
m := make(map[int]int, 0)
return findTargetDFS(root, k, m)
}
func findTargetDFS(root *TreeNode, k int, m map[int]int) bool {
if root == nil {
return false
}
if _, ok := m[k-root.Val]; ok {
return ok
}
m[root.Val]++
return findTargetDFS(root.Left, k, m) || findTargetDFS(root.Right, k, m)
}