/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
func findTarget(root *TreeNode, k int) bool {
var ans []int
var inorder func(*TreeNode)
inorder = func(node *TreeNode) {
if node == nil {
return
}
inorder(node.Left)
ans = append(ans, node.Val)
inorder(node.Right)
}
inorder(root)
left, right := 0, len(ans)-1
for left < right { // 双指针
if ans[left] + ans[right] < k {
left++
} else if ans[left] + ans[right] > k {
right--
} else {
return true
}
}
return false
}