mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-06 23:28:29 +08:00
Update
This commit is contained in:
@ -68,6 +68,7 @@
|
||||
|[0349.两个数组的交集](https://github.com/youngyangyang04/leetcode/blob/master/problems/0349.两个数组的交集.md) |哈希表 |简单|**哈希**|
|
||||
|[0350.两个数组的交集II](https://github.com/youngyangyang04/leetcode/blob/master/problems/0350.两个数组的交集II.md) |哈希表 |简单|**哈希**|
|
||||
|[0383.赎金信](https://github.com/youngyangyang04/leetcode/blob/master/problems/0383.赎金信.md) |数组 |简单|**暴力** **字典计数** **哈希**|
|
||||
|[0450.删除二叉搜索树中的节点](https://github.com/youngyangyang04/leetcode/blob/master/problems/0450.删除二叉搜索树中的节点.md) |树 |中等|**递归**|
|
||||
|[0434.字符串中的单词数](https://github.com/youngyangyang04/leetcode/blob/master/problems/0434.字符串中的单词数.md) |字符串 |简单|**模拟**|
|
||||
|[0454.四数相加II](https://github.com/youngyangyang04/leetcode/blob/master/problems/0454.四数相加II.md) |哈希表 |中等| **哈希**|
|
||||
|[0575.分糖果](https://github.com/youngyangyang04/leetcode/blob/master/problems/0575.分糖果.md) |哈希表 |简单|**哈希**|
|
||||
|
@ -15,8 +15,9 @@ https://leetcode-cn.com/problems/3sum/
|
||||
|
||||
时间复杂度:O(n^2)
|
||||
|
||||
## 哈希法代码
|
||||
|
||||
## C++代码
|
||||
|
||||
### 哈希法代码
|
||||
|
||||
```
|
||||
class Solution {
|
||||
@ -54,7 +55,7 @@ public:
|
||||
}
|
||||
};
|
||||
```
|
||||
## 双指针法代码
|
||||
### 双指针法代码
|
||||
```
|
||||
class Solution {
|
||||
public:
|
||||
|
41
problems/0450.删除二叉搜索树中的节点.md
Normal file
41
problems/0450.删除二叉搜索树中的节点.md
Normal file
@ -0,0 +1,41 @@
|
||||
## 题目地址
|
||||
https://leetcode-cn.com/problems/delete-node-in-a-bst/
|
||||
|
||||
## 思路
|
||||
|
||||
平衡二叉树中删除节点有三种情况
|
||||
|
||||
1. 找到删除的节点,其左节点为空,那么就返回其右节点
|
||||
2. 找到删除的节点,其右节点为空,那么就返回其左节点
|
||||
3. 找到删除的节点,左右孩子节点都不为空,则将左孩子放到右孩子的最左面的节点的左孩子上。
|
||||
|
||||
|
||||
## C++代码
|
||||
|
||||
```
|
||||
class Solution {
|
||||
public:
|
||||
TreeNode* deleteNode(TreeNode* root, int key) {
|
||||
if (root == NULL) return root;
|
||||
if (root->val == key) {
|
||||
if (root->left == NULL) return root->right; // 第一种情况
|
||||
else if (root->right == NULL) return root->left; // 第二种情况
|
||||
else { // 第三种情况
|
||||
TreeNode* cur = root->right;
|
||||
while(cur->left != NULL) {
|
||||
cur = cur->left;
|
||||
}
|
||||
cur->left = root->left;
|
||||
root = root->right;
|
||||
return root;
|
||||
}
|
||||
}
|
||||
if (root->val > key) root->left = deleteNode(root->left, key);
|
||||
if (root->val < key) root->right = deleteNode(root->right, key);
|
||||
return root;
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
|
||||
> 更多算法干货文章持续更新,可以微信搜索「代码随想录」第一时间围观,关注后,回复「Java」「C++」 「python」「简历模板」「数据结构与算法」等等,就可以获得我多年整理的学习资料。
|
@ -40,5 +40,5 @@ public:
|
||||
};
|
||||
```
|
||||
|
||||
> 更过算法干货文章持续更新,可以微信搜索「代码随想录」第一时间围观,关注后,回复「Java」「C++」 「python」「简历模板」「数据结构与算法」等等,就可以获得我多年整理的学习资料。
|
||||
> 更多算法干货文章持续更新,可以微信搜索「代码随想录」第一时间围观,关注后,回复「Java」「C++」 「python」「简历模板」「数据结构与算法」等等,就可以获得我多年整理的学习资料。
|
||||
|
||||
|
Reference in New Issue
Block a user