Skip to content

Commit 36e9dae

Browse files
committed
feat:提交代码和视频链接
1 parent 9f1468c commit 36e9dae

5 files changed

+150
-4
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@
9898
|[leetcode 200.岛屿数量](./leetcode%20blind75/图/LeetCode%200200.岛屿的数量.md)| ✔ | ✔ | ✔ | [岛屿数量](https://www.bilibili.com/video/BV1LUsMezEtq/) | 图
9999
|[leetcode 128.最长连续序列](./leetcode%20blind75/图/LeetCode%200128.%20最长连续序列.md)| ✔ | ✔ | ✔ | [最长连续序列](https://www.bilibili.com/video/BV1qqHKetETN/) | 图
100100
|[leetcode 57.插入区间](./leetcode%20blind75/区间/LeetCode%200057.插入区间.md)| ✔ | ✔ | ✔ | [插入区间](https://www.bilibili.com/video/BV1VHHUezEw7/) | 区间
101-
|[leetcode 56.合并区间](./leetcode%20blind75/区间/LeetCode%200056.%20合并区间.md)| ✔ | ✔ | ✔ | | 区间
102-
|[leetcode 435.无重叠区间](./leetcode%20blind75/区间/LeetCode%200435.%20无重叠区间.md)| ✔ | ✔ | ✔ | | 区间
101+
|[leetcode 56.合并区间](./leetcode%20blind75/区间/LeetCode%200056.%20合并区间.md)| ✔ | ✔ | ✔ | [合并区间](https://www.bilibili.com/video/BV1nVHXehEBC/) | 区间
102+
|[leetcode 435.无重叠区间](./leetcode%20blind75/区间/LeetCode%200435.%20无重叠区间.md)| ✔ | ✔ | ✔ | [无重叠区间](https://www.bilibili.com/video/BV1N2pLeTEUM/) | 区间
103103
|[leetcode 206.反转链表](./leetcode%20blind75/链表/LeetCode%200206.%20%E5%8F%8D%E8%BD%AC%E9%93%BE%E8%A1%A8.md)| ✔ | ✔ | ✔ | [反转链表](https://www.bilibili.com/video/BV1gE421N7W2/) | 链表
104104
|[leetcode 141.环形链表](./leetcode%20blind75/链表/LeetCode%200141.%E7%8E%AF%E5%BD%A2%E9%93%BE%E8%A1%A8.md)| ✔ | ✔ | ✔ | [环形链表](https://www.bilibili.com/video/BV18z421q78k/) | 链表
105105
|[leetcode 21.合并两个有序链表](./leetcode%20blind75/链表/LeetCode%200021.%20%E5%90%88%E5%B9%B6%E4%B8%A4%E4%B8%AA%E6%9C%89%E5%BA%8F%E9%93%BE%E8%A1%A8.md)| ✔ | ✔ | ✔ | [合并两个有序链表](https://www.bilibili.com/video/BV17w4m1Y7CJ/) | 链表
@@ -121,11 +121,11 @@
121121
|[leetcode 647.回文子串](./leetcode%20blind75/字符串/LeetCode%200647.%20回文子串.md)| ✔ | ✔ | ✔ | [回文子串](https://www.bilibili.com/video/BV1Bs421w7iw/) | 字符串
122122
|[leetcode 104.二叉树的最大深度](./leetcode%20blind75/树/LeetCode%200104.%20二叉树的最大深度.md)| ✔ | ✔ | ✔ | [二叉树的最大深度](https://www.bilibili.com/video/BV1MRYHeHEeP/) | 树
123123
|[leetcode 100.相同的树](./leetcode%20blind75/树/LeetCode%200100.%20相同的树.md) | ✔ | ✔ | ✔ | [相同的树](https://www.bilibili.com/video/BV163Ype6E2L/) | 树
124-
|[leetcode 226.翻转二叉树](./leetcode%20blind75/树/LeetCode%200226.%20翻转二叉树.md) | ✔ | ✘ | ✘ | [翻转二叉树](https://www.bilibili.com/video/BV1N7YheBE8H/) | 树
124+
|[leetcode 226.翻转二叉树](./leetcode%20blind75/树/LeetCode%200226.%20翻转二叉树.md) | ✔ | ✔ | ✔ | [翻转二叉树](https://www.bilibili.com/video/BV1N7YheBE8H/) | 树
125125
|[leetcode 124.二叉树中的最大路径和](./leetcode%20blind75/树/LeetCode%200124.%20二叉树中的最大路径和.md) | ✔ | ✘ | ✘ | [二叉树中的最大路径和](https://www.bilibili.com/video/BV12FYee2Eg6/) | 树
126126
|[leetcode 102.二叉树的层序遍历](./leetcode%20blind75/树/LeetCode%200102.%20二叉树的层序遍历.md) | ✔ | ✔ | ✔ | [二叉树的层序遍历](https://www.bilibili.com/video/BV1MNeceFE1h/) | 树
127127
|[leetcode 297.二叉树的序列化与反序列化](./leetcode%20blind75/树/LeetCode%200297.%20二叉树的序列化与反序列化.md) | ✔ | ✘ | ✘ | [二叉树的序列化与反序列化](https://www.bilibili.com/video/BV1TTeceoECg/) | 树
128-
|[leetcode 572.另一棵树的子树](./leetcode%20blind75/树/LeetCode%200572.%20另一棵树的子树.md) | ✔ | ✘ | ✘ | [另一棵树的子树](https://www.bilibili.com/video/BV1BseceLE6R/) | 树
128+
|[leetcode 572.另一棵树的子树](./leetcode%20blind75/树/LeetCode%200572.%20另一棵树的子树.md) | ✔ | ✔ | ✔ | [另一棵树的子树](https://www.bilibili.com/video/BV1BseceLE6R/) | 树
129129
|[leetcode 105.从前序与中序遍历序列构造二叉树](./leetcode%20blind75/树/LeetCode%200105.%20从前序与中序遍历序列构造二叉树.md) | ✔ | ✘ | ✘ | [从前序与中序遍历序列构造二叉树](https://www.bilibili.com/video/BV1XAYke2ETp/) | 树
130130
|[leetcode 98.验证二叉搜索树](./leetcode%20blind75/树/LeetCode%200098.%20验证二叉搜索树.md) | ✔ | ✔ | ✔ | [验证二叉搜索树](https://www.bilibili.com/video/BV1zVe7eoEiu/) | 树
131131
|[leetcode 230.二叉搜索树中第K小的元素](./leetcode%20blind75/树/LeetCode%200230.%20二叉搜索树中第K小的元素.md) | ✔ | ✘ | ✘ | [二叉搜索树中第K小的元素](https://www.bilibili.com/video/BV1DseseYE38/) | 树

leetcode blind75/区间/LeetCode 0056. 合并区间.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
> *题目链接:* https://leetcode.cn/problems/merge-intervals/
2+
>
3+
>*视频题解:* https://www.bilibili.com/video/BV1nVHXehEBC/
24
35
# LeetCode 56. 合并区间
46

leetcode blind75/区间/LeetCode 0435. 无重叠区间.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
> *题目链接:* https://leetcode.cn/problems/non-overlapping-intervals/
2+
>
3+
>*视频题解:* https://www.bilibili.com/video/BV1N2pLeTEUM/
24
35
# LeetCode 435. 无重叠区间
46

leetcode blind75/树/LeetCode 0226. 翻转二叉树.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,69 @@ public:
6262
}
6363
};
6464
```
65+
## java代码
66+
67+
```java
68+
/**
69+
* Definition for a binary tree node.
70+
* public class TreeNode {
71+
* int val;
72+
* TreeNode left;
73+
* TreeNode right;
74+
* TreeNode() {}
75+
* TreeNode(int val) { this.val = val; }
76+
* TreeNode(int val, TreeNode left, TreeNode right) {
77+
* this.val = val;
78+
* this.left = left;
79+
* this.right = right;
80+
* }
81+
* }
82+
*/
83+
class Solution {
84+
public TreeNode invertTree(TreeNode root) {
85+
if (root == null) { // 如果节点为空,返回该节点
86+
return root;
87+
}
88+
89+
// 递归地翻转左子树和右子树
90+
root.left = invertTree(root.left);
91+
root.right = invertTree(root.right);
92+
93+
// 交换左子树和右子树
94+
TreeNode tmp = root.left;
95+
root.left = root.right;
96+
root.right = tmp;
97+
98+
return root;
99+
}
100+
}
101+
```
102+
103+
## python代码
104+
105+
```python
106+
# Definition for a binary tree node.
107+
# class TreeNode:
108+
# def __init__(self, val=0, left=None, right=None):
109+
# self.val = val
110+
# self.left = left
111+
# self.right = right
112+
class Solution:
113+
def invertTree(self, root: Optional[TreeNode]) -> Optional[TreeNode]:
114+
if not root: # 如果节点为空,返回该节点
115+
return root
116+
117+
# 递归地翻转左子树和右子树
118+
root.left = self.invertTree(root.left)
119+
root.right = self.invertTree(root.right)
120+
121+
# 交换左子树和右子树
122+
tmp = root.left
123+
root.left = root.right
124+
root.right = tmp
125+
126+
return root
127+
```
65128

66129
## 复杂度分析
67130

leetcode blind75/树/LeetCode 0572. 另一棵树的子树.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,85 @@ public:
7474
};
7575
```
7676

77+
## java代码
78+
79+
```java
80+
/**
81+
* Definition for a binary tree node.
82+
* public class TreeNode {
83+
* int val;
84+
* TreeNode left;
85+
* TreeNode right;
86+
* TreeNode() {}
87+
* TreeNode(int val) { this.val = val; }
88+
* TreeNode(int val, TreeNode left, TreeNode right) {
89+
* this.val = val;
90+
* this.left = left;
91+
* this.right = right;
92+
* }
93+
* }
94+
*/
95+
class Solution {
96+
public boolean isSubtree(TreeNode root, TreeNode subRoot) {
97+
// 递归结束的条件,空节点null是任意树的子树
98+
if (subRoot == null) return true;
99+
// 递归结束的条件,此时subRoot不为null
100+
if (root == null) return false;
101+
// 递归结束的条件
102+
if (isSameTree(root, subRoot)) return true;
103+
// 子问题
104+
return isSubtree(root.left, subRoot) || isSubtree(root.right, subRoot);
105+
}
106+
107+
public boolean isSameTree(TreeNode p, TreeNode q) {
108+
// 递归结束的条件
109+
if (p == null && q == null) {
110+
return true;
111+
}
112+
// 递归结束的条件
113+
if (p == null || q == null || p.val != q.val) {
114+
return false;
115+
}
116+
// 子问题
117+
return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
118+
}
119+
}
120+
```
121+
122+
## python代码
123+
124+
```python
125+
# Definition for a binary tree node.
126+
# class TreeNode:
127+
# def __init__(self, val=0, left=None, right=None):
128+
# self.val = val
129+
# self.left = left
130+
# self.right = right
131+
class Solution:
132+
def isSubtree(self, root: Optional[TreeNode], subRoot: Optional[TreeNode]) -> bool:
133+
# 递归结束的条件,空节点None是任意树的子树
134+
if not subRoot:
135+
return True
136+
# 递归结束的条件,此时subRoot不为None
137+
if not root:
138+
return False
139+
# 递归结束的条件
140+
if self.isSameTree(root, subRoot):
141+
return True
142+
# 子问题
143+
return self.isSubtree(root.left, subRoot) or self.isSubtree(root.right, subRoot)
144+
145+
def isSameTree(self, p: TreeNode, q: TreeNode) -> bool:
146+
# 递归结束的条件
147+
if not p and not q:
148+
return True
149+
# 递归结束的条件
150+
if not p or not q or p.val != q.val:
151+
return False
152+
# 子问题
153+
return self.isSameTree(p.left, q.left) and self.isSameTree(p.right, q.right)
154+
```
155+
77156
## 复杂度分析
78157

79158
**时间复杂度:** 由于`s`的每一个节点都要与`t`进行去匹配,所以时间复杂度为 *O(ST)*,其中`S``s`的节点数量,`T``t`的节点数量。

0 commit comments

Comments
 (0)