class Solution(object):
def findTarget(self, root, k):
def inorder(node):
if not node:
return []
return inorder(node.left) + [node.val] + inorder(node.right)
alist = inorder(root)
left, right = 0, len(alist) -1
while left < right:
sum_ = alist[left] + alist[right]
if sum_ == k:
return True
if sum_ > k:
right -= 1
else:
left += 1
return False
leetcode-二叉搜索树先关题目
最新推荐文章于 2024-07-13 18:57:33 发布