Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[pull] master from youngyangyang04:master #272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
pull merged 41 commits into AlgorithmAndLeetCode:master from youngyangyang04:master
May 27, 2023
Merged
Changes from 3 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
4b575a8
Update 0450.删除二叉搜索树中的节点.md
fwqaaq Dec 7, 2022
d97f276
Update problems/0450.删除二叉搜索树中的节点.md
fwqaaq Dec 9, 2022
94f79ad
Update 0001.两数之和.md
coffeelize Mar 19, 2023
633cb54
为0226.翻转二叉树添加了C#语言版(包含递归和迭代)
JavieDeng Mar 20, 2023
da2acd7
"为0226.翻转二叉树添加了C#语言版(包含递归和迭代)"
JavieDeng Mar 20, 2023
0231e5f
Merge branch 'youngyangyang04:master' into master
JavieDeng Mar 22, 2023
f51f312
Update 0406.根据身高重建队列.md
fwqaaq Mar 23, 2023
b934f47
Update 0647.回文子串.md
milu-tao Mar 24, 2023
40f8230
Update 0106.从中序与后序遍历序列构造二叉树.md
jianghongcheng May 9, 2023
7eea41e
Update 0654.最大二叉树.md
jianghongcheng May 9, 2023
a45046b
Update 0617.合并二叉树.md
jianghongcheng May 9, 2023
3818de4
Update 0700.二叉搜索树中的搜索.md
jianghongcheng May 9, 2023
f5329cd
Update 0110.平衡二叉树.md
jianghongcheng May 22, 2023
2024fc2
Update 0257.二叉树的所有路径.md
jianghongcheng May 22, 2023
9b770de
Update 0257.二叉树的所有路径.md
jianghongcheng May 22, 2023
1a67274
Update 0257.二叉树的所有路径.md
jianghongcheng May 22, 2023
2e81b18
Update 0257.二叉树的所有路径.md
jianghongcheng May 23, 2023
117ef69
Update 0404.左叶子之和.md
jianghongcheng May 23, 2023
1ac1a8c
Update 0513.找树左下角的值.md
jianghongcheng May 23, 2023
12634b2
Update 0654.最大二叉树.md
jianghongcheng May 23, 2023
41cf3a4
Update 0654.最大二叉树.md
jianghongcheng May 23, 2023
7a544d9
Update 0654.最大二叉树.md
jianghongcheng May 23, 2023
62d48cf
Merge pull request #2083 from jianghongcheng/master
youngyangyang04 May 23, 2023
3f4968a
Merge pull request #1978 from milu-tao/master
youngyangyang04 May 24, 2023
2b2fd97
Merge pull request #1976 from fwqaaq/patch-23
youngyangyang04 May 24, 2023
442349a
Merge pull request #1968 from JavieDeng/master
youngyangyang04 May 24, 2023
58fb2cb
Merge pull request #1807 from fwqaaq/patch-11
youngyangyang04 May 24, 2023
3058654
Update 0098.验证二叉搜索树.md
jianghongcheng May 24, 2023
85e4c41
Update 0530.二叉搜索树的最小绝对差.md
jianghongcheng May 24, 2023
c5d1845
Update 0501.二叉搜索树中的众数.md
jianghongcheng May 24, 2023
daa5417
Update 0236.二叉树的最近公共祖先.md
jianghongcheng May 24, 2023
e7b7aa8
Update 0235.二叉搜索树的最近公共祖先.md
jianghongcheng May 24, 2023
511bf44
Update 0701.二叉搜索树中的插入操作.md
jianghongcheng May 24, 2023
731d1ca
Update 0450.删除二叉搜索树中的节点.md
jianghongcheng May 24, 2023
5365274
Update 0669.修剪二叉搜索树.md
jianghongcheng May 24, 2023
76e3811
Update 0108.将有序数组转换为二叉搜索树.md
jianghongcheng May 24, 2023
14acf5a
Update 0538.把二叉搜索树转换为累加树.md
jianghongcheng May 24, 2023
450b3f2
Update 0111.二叉树的最小深度.md
jianghongcheng May 24, 2023
832897e
Update 0110.平衡二叉树.md
jianghongcheng May 24, 2023
d420634
Merge pull request #2096 from jianghongcheng/master
youngyangyang04 May 25, 2023
44477f8
Merge pull request #1962 from coffeelize/patch-1
youngyangyang04 May 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions problems/0450.删除二叉搜索树中的节点.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,40 @@ object Solution {
}
```

## rust

```rust
impl Solution {
pub fn delete_node(
root: Option<Rc<RefCell<TreeNode>>>,
key: i32,
) -> Option<Rc<RefCell<TreeNode>>> {
root.as_ref()?;

let mut node = root.as_ref().unwrap().borrow_mut();
match node.val.cmp(&key) {
std::cmp::Ordering::Less => node.right = Self::delete_node(node.right.clone(), key),
std::cmp::Ordering::Equal => match (node.left.clone(), node.right.clone()) {
(None, None) => return None,
(None, Some(r)) => return Some(r),
(Some(l), None) => return Some(l),
(Some(l), Some(r)) => {
let mut cur = Some(r.clone());
while let Some(n) = cur.clone().unwrap().borrow().left.clone() {
cur = Some(n);
}
cur.unwrap().borrow_mut().left = Some(l);
return Some(r);
}
},
std::cmp::Ordering::Greater => node.left = Self::delete_node(node.left.clone(), key),
}
drop(node);
root
}
}
```

<p align="center">
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
Expand Down

AltStyle によって変換されたページ (->オリジナル) /