701. Insert into a Binary Search Tree
701. Insert into a Binary Search Tree - Medium
二叉搜索树的题目都大同小异,基本上一个模版就能搞定。
Description¶
701. Insert into a Binary Search Tree
You are given the root
node of a binary search tree (BST) and a value
to insert into the tree. Return the root node of the BST after the insertion. It is guaranteed that the new value does not exist in the original BST.
Notice that there may exist multiple valid ways for the insertion, as long as the tree remains a BST after insertion. You can return any of them.
题意就是让我们将一个数插入到二叉搜索树中,因为二叉搜索树的特性,这道题就很简单了,直接上模版。一般递归就能解决
Solution¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
|