File tree Expand file tree Collapse file tree 4 files changed +47
-4
lines changed Expand file tree Collapse file tree 4 files changed +47
-4
lines changed Original file line number Diff line number Diff line change 6868| [ 0349.两个数组的交集] ( https://github.com/youngyangyang04/leetcode/blob/master/problems/0349.两个数组的交集.md ) | 哈希表 | 简单| ** 哈希** |
6969| [ 0350.两个数组的交集II] ( https://github.com/youngyangyang04/leetcode/blob/master/problems/0350.两个数组的交集II.md ) | 哈希表 | 简单| ** 哈希** |
7070| [ 0383.赎金信] ( https://github.com/youngyangyang04/leetcode/blob/master/problems/0383.赎金信.md ) | 数组 | 简单| ** 暴力** ** 字典计数** ** 哈希** |
71+ | [ 0450.删除二叉搜索树中的节点] ( https://github.com/youngyangyang04/leetcode/blob/master/problems/0450.删除二叉搜索树中的节点.md ) | 树 | 中等| ** 递归** |
7172| [ 0434.字符串中的单词数] ( https://github.com/youngyangyang04/leetcode/blob/master/problems/0434.字符串中的单词数.md ) | 字符串 | 简单| ** 模拟** |
7273| [ 0454.四数相加II] ( https://github.com/youngyangyang04/leetcode/blob/master/problems/0454.四数相加II.md ) | 哈希表 | 中等| ** 哈希** |
7374| [ 0575.分糖果] ( https://github.com/youngyangyang04/leetcode/blob/master/problems/0575.分糖果.md ) | 哈希表 | 简单| ** 哈希** |
Original file line number Diff line number Diff line change @@ -15,8 +15,9 @@ https://leetcode-cn.com/problems/3sum/
1515
1616时间复杂度:O(n^2)
1717
18- ## 哈希法代码
19-
18+ ## C++代码
19+
20+ ### 哈希法代码
2021
2122```
2223class Solution {
@@ -54,7 +55,7 @@ public:
5455 }
5556};
5657```
57- ## 双指针法代码
58+ ### 双指针法代码
5859```
5960class Solution {
6061public:
Original file line number Diff line number Diff line change 1+ ## 题目地址
2+ https://leetcode-cn.com/problems/delete-node-in-a-bst/
3+
4+ ## 思路
5+
6+ 平衡二叉树中删除节点有三种情况
7+
8+ 1 . 找到删除的节点,其左节点为空,那么就返回其右节点
9+ 2 . 找到删除的节点,其右节点为空,那么就返回其左节点
10+ 3 . 找到删除的节点,左右孩子节点都不为空,则将左孩子放到右孩子的最左面的节点的左孩子上。
11+
12+
13+ ## C++代码
14+
15+ ```
16+ class Solution {
17+ public:
18+ TreeNode* deleteNode(TreeNode* root, int key) {
19+ if (root == NULL) return root;
20+ if (root->val == key) {
21+ if (root->left == NULL) return root->right; // 第一种情况
22+ else if (root->right == NULL) return root->left; // 第二种情况
23+ else { // 第三种情况
24+ TreeNode* cur = root->right;
25+ while(cur->left != NULL) {
26+ cur = cur->left;
27+ }
28+ cur->left = root->left;
29+ root = root->right;
30+ return root;
31+ }
32+ }
33+ if (root->val > key) root->left = deleteNode(root->left, key);
34+ if (root->val < key) root->right = deleteNode(root->right, key);
35+ return root;
36+ }
37+ };
38+ ```
39+
40+
41+ > 更多算法干货文章持续更新,可以微信搜索「代码随想录」第一时间围观,关注后,回复「Java」「C++」 「python」「简历模板」「数据结构与算法」等等,就可以获得我多年整理的学习资料。
Original file line number Diff line number Diff line change @@ -40,5 +40,5 @@ public:
4040};
4141```
4242
43- > 更过算法干货文章持续更新 ,可以微信搜索「代码随想录」第一时间围观,关注后,回复「Java」「C++」 「python」「简历模板」「数据结构与算法」等等,就可以获得我多年整理的学习资料。
43+ > 更多算法干货文章持续更新 ,可以微信搜索「代码随想录」第一时间围观,关注后,回复「Java」「C++」 「python」「简历模板」「数据结构与算法」等等,就可以获得我多年整理的学习资料。
4444
You can’t perform that action at this time.
0 commit comments