当前位置:网站首页>12.<tag-二叉树和BST基础>lt.701. 二叉搜索树中的插入操作 dbc
12.<tag-二叉树和BST基础>lt.701. 二叉搜索树中的插入操作 dbc
2022-06-09 11:15:00 【菜菜的大数据开发之路】
X.<tag-数组和二分查找>-lt.xx-xxxxxx + lt.xx-xxxxxx
lt.701. 二叉搜索树中的插入操作
[案例需求]

[思路分析一, 带返回值的递归]

[代码实现]
class Solution {
//1. 递归函数, 插入值到树中, 返回值, 这棵树的根节点
public TreeNode insertIntoBST(TreeNode root, int val) {
//2. 递归结束条件
if(root == null)return new TreeNode(val); //返回的是新节点
if(root.val > val) root.left = insertIntoBST(root.left, val);
if(root.val < val) root.right = insertIntoBST(root.right, val);
return root;
}
}
[思路分析二, 不带返回值的递归]

[代码实现]
[思路分析三, 迭代法]

边栏推荐
猜你喜欢
随机推荐
HEVC之HM学习01
08 | middle stage landing step 3: middle stage planning and design
8. search insertion position
09 | 中台落地第四步:中台的建设与接入(Delivery)
08 | 中台落地第三步:中台的规划与设计(Design)
[patch analysis] cve-2016-8610: patch analysis of "SSL death alert" vulnerability leading to denial of service
电脑快速索引查询软件Listary
01 | context: why is Zhongtai so popular?
RestTemplate使用详解及踩坑记录
Popt easy to use
R语言使用glm构建logistic回归模型,构建多个协变量和分组变量之间的关系模型进行倾向性评分计算、估计(Propensity score)、预测倾向性评分并可视化不同分组倾向性评分的分布
Map的遍历几种方式
Chapter II Application Layer
10 | summary: summary of middle platform landing tool resources
[signalr complete series] Realization of signalr real-time communication in net core
7. remove elements
如何解决存在的1px问题?
浅谈Event-Loop
H3C认证无线互联网络专家
工具类记录之Guawa的Splitter









![[data center stage] 00 opening words data center stage, is it a trap? Or the golden key?](/img/19/256cdcf783986d1012ddc75c8b2c31.png)