1
# Definition for a binary tree node.
2
# class TreeNode:
3
# def __init__(self, val=0, left=None, right=None):
4
# self.val = val
5
# self.left = left
6
# self.right = right
7
class Solution:
8
def findTarget(self, root: Optional[TreeNode], k: int) -> bool:
9
def inorder(root, l):
10
if root:
11
inorder(root.left, l)
12
l.append(root.val)
13
inorder(root.right, l)
14

15
l = []
16
inorder(root, l)
17
left, right = 0, len(l) - 1
18
while left != right:
19
sum = l[left] + l[right]
20
if sum > k:
21
right -= 1
22
elif sum < k:
23
left += 1
24
else:
25
return 1
26
return 0

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0