Given the root node of a binary search tree (BST) and a value. You need to find the node in the BST that the node's value equals the given value. Return the subtree rooted with that node. If such node doesn't exist, you should return NULL.
Note that an empty tree is represented byNULL
, therefore you would see the expected output (serialized tree format) as[]
, notnull
.
給予一個BST的樹根和一個值。你需要找到BST中哪個節點的值和給予的值相等。回傳該節點為樹根的子樹。如果該節點不存在,你應該回傳NULL。
注意到一個空的樹應該用NULL
表示,因此你會看到預期輸出(序列化輸出)是[]
而非null
。
LeetCode
C++