701.Insert into a Binary Search Tree

原题&翻译

Given the root node of a binary search tree (BST) and a value to be inserted into the tree, insert the value into the BST. Return the root node of the BST after the insertion. It is guaranteed that the new value does not exist in the original BST.
给出二叉搜索树根节点, 并给出一个待插入的值. 本题保证待查入值不重复

Note 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.
注意, 这里存在多种插入方案, 只要保证最终结果任是搜索树.

结果 1

结果2


解题

  1. 方案 A, 找到最适合的空节点位置, 插入之, 但是如下代码存在重复插入的运算

via: 701. Insert into a Binary Search Tree

Hello world!
文章已创建 197

相关文章

开始在上面输入您的搜索词,然后按回车进行搜索。按ESC取消。

返回顶部