Last updated
Was this helpful?
Last updated
Was this helpful?
Given a Binary Search Tree and a target number, return true if there exist two elements in the BST such that their sum is equal to the given target.
Example 1:
Example 2:
这题一看想了半天好像还是不能利用BST的性质,其实就是2 Sum,只是多了一步树的遍历而已。btw,怎么遍历都行,这里用了中序。其实递归的,BFS的都行。
再来一个递归的: