网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
TreeNode curr=root;
while(curr!=null){
if(curr.val==val){
return curr;
}else if(curr.val<val){
curr=curr.right;
}else{
curr=curr.left;
}
}
//循环外面说明没有找到
return null;
}
## 🍊3.二叉搜索树的插入
[NC372 插入二叉搜索树](https://bbs.csdn.net/forums/4f45ff00ff254613a03fab5e56a57acb)
>
> **二叉搜索树的插入需要考虑下面几种情况**
>
>
> 1️⃣**根节点为空,那么待插入的节点就作为二叉搜索树的根节点**
> 2️⃣**根节点非空,则找到待插入的位置**
>
>
> ![在这里插入图片描述](https://img-blog.csdnimg.cn/d6e152c25143471b86d2ace5e988283f.png)
>
>
>
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param root TreeNode类
* @param val int整型
* @return TreeNode类
*/
public TreeNode insertToBST (TreeNode root, int val) {
// write code here
if(rootnull) return new TreeNode(val);
TreeNode curr=root;
TreeNode parent=null;
while(curr!=null){
if(curr.valval){
break;
}else if(curr.val<val){
parent=curr;
curr=curr.right;
}else{
parent=curr;
curr=curr.left;
}
}
if(curr==parent.left){
parent.left=new TreeNode(val);
}else{
parent.right=new TreeNode(val);
}
return root;
}
}
## 🍊4.删除二叉搜索树中的一个节点(较复杂)
[NC297 删除一个二叉搜索树中的节点](https://bbs.csdn.net/forums/4f45ff00ff254613a03fab5e56a57acb)
![在这里插入图片描述](https://img-blog.csdnimg.cn/3daded9a0f0349308731780ce492dc02.png)
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param root TreeNode类
* @param key int整型
* @return TreeNode类
*/
public TreeNode deleteNode(TreeNode root, int key) {
root = delete(root,key);
return root;
}
private TreeNode delete(TreeNode root, int key) {
if (root == null) return null;
if (root.val > key) {
root.left = delete(root.left,key);
} else if (root.val < key) {
root.right = delete(root.right,key);
} else {
if (root.left == null) return root.right;
if (root.right == null) return root.left;
TreeNode tmp = root.right;
while (tmp.left != null) {
tmp = tmp.left;
}
root.val = tmp.val;
root.right = delete(root.right,tmp.val);
}
return root;
}
}
## 🍊5.判断是不是二叉搜索树(易错)
[NC184 判断是不是二叉搜索树](https://bbs.csdn.net/forums/4f45ff00ff254613a03fab5e56a57acb)
>
> **判断是不是二叉搜索树,就是看这棵二叉树是否满足二叉搜索树的性质,当二叉搜索树进行中序遍历的时候,它们的节点的值是按照从小到大排序的,我们可以利用这个性质来解答。**![在这里插入图片描述](https://img-blog.csdnimg.cn/82e3d7f5266a4b4bbcc3e7da938f75de.png)
>
>
>
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param root TreeNode类
* @return bool布尔型
*/
long pre = Long.MIN_VALUE;
public boolean isValidBST(TreeNode root) {
if (root == null) {
return true;
}
// 访问左子树
if (!isValidBST(root.left)) {
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
,真正体系化!**
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新