Skip to content

Commit

Permalink
调整添加的c++代码格式,与整体统一
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryhsman committed Sep 6, 2021
1 parent e0d7186 commit 0fa9cc1
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions problems/0450.删除二叉搜索树中的节点.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,20 @@ public:
if (root == nullptr) return root; // 第一种情况:没找到删除的节点,遍历到空节点直接返回了
if (root->val == key) {
// 第二种情况:左右孩子都为空(叶子节点),直接删除节点, 返回NULL为根节点
if (root->left == nullptr && root->right == nullptr)
{
if (root->left == nullptr && root->right == nullptr) {
///! 内存释放
delete root;
return nullptr;
}
// 第三种情况:其左孩子为空,右孩子不为空,删除节点,右孩子补位 ,返回右孩子为根节点
else if (root->left == nullptr)
{
else if (root->left == nullptr) {
auto retNode = root->right;
///! 内存释放
delete root;
return retNode;
}
// 第四种情况:其右孩子为空,左孩子不为空,删除节点,左孩子补位,返回左孩子为根节点
else if (root->right == nullptr)
{
else if (root->right == nullptr) {
auto retNode = root->left;
///! 内存释放
delete root;
Expand Down

0 comments on commit 0fa9cc1

Please sign in to comment.