Skip to content

Commit 6044e75

Browse files
author
lucifer
committed
fix: $$ -> $
1 parent 6797afd commit 6044e75

File tree

191 files changed

+1446
-1472
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

191 files changed

+1446
-1472
lines changed

91/binary-search.md

+13-13
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@
5454

5555
**复杂度分析**
5656

57-
- 平均时间复杂度: $$O(logN)$$
58-
- 最坏时间复杂度: $$O(logN)$$
59-
- 最优时间复杂度: $$O(1)$$
57+
- 平均时间复杂度: $O(logN)$
58+
- 最坏时间复杂度: $O(logN)$
59+
- 最优时间复杂度: $O(1)$
6060
- 空间复杂度
61-
- 迭代: $$O(1)$$
62-
- 递归: $$O(logN)$$(无尾调用消除)
61+
- 迭代: $O(1)$
62+
- 递归: $O(logN)$(无尾调用消除)
6363

6464
> 后面的复杂度也是类似的,不再赘述。
6565
@@ -621,8 +621,8 @@ class Solution:
621621

622622
**复杂度分析**
623623

624-
- 时间复杂度:$$O(log N)$$
625-
- 空间复杂度:$$O(1)$$
624+
- 时间复杂度:$O(log N)$
625+
- 空间复杂度:$O(1)$
626626

627627
##### 扩展
628628

@@ -745,8 +745,8 @@ class Solution:
745745

746746
**复杂度分析**
747747

748-
- 时间复杂度:最坏的情况是只有一行或者只有一列,此时时间复杂度为 $$O(M * N)$$。更多的情况下时间复杂度为 $$O(M + N)$$
749-
- 空间复杂度:$$O(1)$$
748+
- 时间复杂度:最坏的情况是只有一行或者只有一列,此时时间复杂度为 $O(M * N)$。更多的情况下时间复杂度为 $O(M + N)$
749+
- 空间复杂度:$O(1)$
750750

751751
力扣 [240. 搜索二维矩阵 II](https://leetcode-cn.com/problems/search-a-2d-matrix-ii/) 发生了一点变化,不再是`每行的第一个整数大于前一行的最后一个整数`,而是 `每列的元素从上到下升序排列`。我们仍然可以选择左下进行二分。
752752

@@ -825,8 +825,8 @@ class Solution:
825825

826826
**复杂度分析**
827827

828-
- 时间复杂度:$$O(log N)$$
829-
- 空间复杂度:$$O(1)$$
828+
- 时间复杂度:$O(log N)$
829+
- 空间复杂度:$O(1)$
830830

831831
##### 另一种二分法
832832

@@ -904,8 +904,8 @@ class Solution:
904904

905905
**复杂度分析**
906906

907-
- 时间复杂度:$$O(log N)$$
908-
- 空间复杂度:$$O(1)$$
907+
- 时间复杂度:$O(log N)$
908+
- 空间复杂度:$O(1)$
909909

910910
### 二叉树
911911

daily/2019-08-09.md

+17-12
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
# 毎日一题 - 64.最小路径和
1+
# 毎日一题 - 64.最小路径和
22

33
## 信息卡片
44

5-
* 时间:2019-08-09
6-
* 题目链接:https://leetcode-cn.com/problems/minimum-path-sum/
7-
- tag:`动态规划` `Array`
5+
- 时间:2019-08-09
6+
- 题目链接:https://leetcode-cn.com/problems/minimum-path-sum/
7+
8+
* tag:`动态规划` `Array`
9+
810
## 题目描述
9-
给定一个包含非负整数的 m x n 网格,请找出一条从左上角到右下角的路径,使得路径上的数字总和为最小。
11+
12+
给定一个包含非负整数的  m x n  网格,请找出一条从左上角到右下角的路径,使得路径上的数字总和为最小。
1013
**说明**:每次只能向下或者向右移动一步。
1114
**示例:**
15+
1216
```
1317
输入:
1418
[
@@ -19,12 +23,12 @@
1923
输出: 7
2024
解释: 因为路径 1→3→1→1→1 的总和最小。
2125
```
22-
## 参考答案
2326

24-
我们新建一个额外的dp数组,与原矩阵大小相同。在这个矩阵中,dp(i,j)表示从原点到坐标(i,j)的最小路径和。我们初始化dp值为对应的原矩阵值,然后去填整个矩阵,对于每个元素考虑从上方移动过来还是从左方移动过来,因此获得最小路径和我们有如下递推公式:`dp(i,j)=grid(i,j)+min(dp(i-1,j),dp(i,j-1))`
27+
## 参考答案
2528

29+
我们新建一个额外的 dp 数组,与原矩阵大小相同。在这个矩阵中,dp(i,j)表示从原点到坐标(i,j)的最小路径和。我们初始化 dp 值为对应的原矩阵值,然后去填整个矩阵,对于每个元素考虑从上方移动过来还是从左方移动过来,因此获得最小路径和我们有如下递推公式:`dp(i,j)=grid(i,j)+min(dp(i-1,j),dp(i,j-1))`
2630

27-
我们可以使用原地算法,这样就不需要开辟dp数组,空间复杂度可以降低到$$O(1)$$
31+
我们可以使用原地算法,这样就不需要开辟 dp 数组,空间复杂度可以降低到$O(1)$。
2832

2933
```c++
3034
class Solution {
@@ -46,7 +50,7 @@ public:
4650
{
4751
grid[i][0] += grid[i-1][0];
4852
}
49-
53+
5054
for(int i=1;i<n;i++)
5155
{
5256
for(int j=1;j<m;j++)
@@ -60,10 +64,11 @@ public:
6064
};
6165
```
6266

63-
6467
**复杂度分析**
65-
- 时间复杂度:$$O(M * N)$$
66-
- 空间复杂度:$$O(1)$$
68+
69+
- 时间复杂度:$O(M * N)$
70+
- 空间复杂度:$O(1)$
71+
6772
## 其他优秀解答
6873

6974
> 暂缺

problems/1.two-sum.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ public:
109109
110110
**复杂度分析**
111111
112-
- 时间复杂度:$$O(N)$$
113-
- 空间复杂度:$$O(N)$$
112+
- 时间复杂度:$O(N)$
113+
- 空间复杂度:$O(N)$
114114
115115
更多题解可以访问我的 LeetCode 题解仓库:https://github.com/azl397985856/leetcode 。 目前已经 37K star 啦。
116116

problems/100.same-tree.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ public:
136136
137137
**复杂度分析**
138138
139-
- 时间复杂度:$$O(N)$$,其中 N 为树的节点数。
140-
- 空间复杂度:$$O(h)$$,其中 h 为树的高度。
139+
- 时间复杂度:$O(N)$,其中 N 为树的节点数。
140+
- 空间复杂度:$O(h)$,其中 h 为树的高度。
141141
142142
## 层序遍历
143143
@@ -196,8 +196,8 @@ function isSameNode(nodeA, nodeB) {
196196

197197
**复杂度分析**
198198

199-
- 时间复杂度:$$O(N)$$,其中 N 为树的节点数。
200-
- 空间复杂度:$$O(Q)$$,其中 Q 为队列的长度最大值,在这里不会超过相邻两层的节点数的最大值。
199+
- 时间复杂度:$O(N)$,其中 N 为树的节点数。
200+
- 空间复杂度:$O(Q)$,其中 Q 为队列的长度最大值,在这里不会超过相邻两层的节点数的最大值。
201201

202202
## 前中序确定一棵树
203203

@@ -248,5 +248,5 @@ function inorder(root, arr) {
248248

249249
**复杂度分析**
250250

251-
- 时间复杂度:$$O(N)$$,其中 N 为树的节点数。
252-
- 空间复杂度:使用了中序遍历的结果数组,因此空间复杂度为 $$O(N)$$,其中 N 为树的节点数。
251+
- 时间复杂度:$O(N)$,其中 N 为树的节点数。
252+
- 空间复杂度:使用了中序遍历的结果数组,因此空间复杂度为 $O(N)$,其中 N 为树的节点数。

problems/101.symmetric-tree.md

+8-5
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,11 @@ return True
9898
> 其实更像本题一点的话应该是从中间分别向两边扩展 😂
9999
100100
## 代码
101+
101102
代码支持:C++, Java, Python3
102103

103104
C++ Code:
105+
104106
```c++
105107
/**
106108
* Definition for a binary tree node.
@@ -123,7 +125,7 @@ public:
123125
{
124126
return true;
125127
}
126-
// 只存在一个子节点 或者左右不相等
128+
// 只存在一个子节点 或者左右不相等
127129
if(l==NULL || r==NULL || l->val != r->val)
128130
{
129131
return false;
@@ -134,8 +136,8 @@ public:
134136
};
135137
```
136138

137-
138139
Java Code:
140+
139141
```java
140142
/**
141143
* Definition for a binary tree node.
@@ -164,7 +166,7 @@ class Solution {
164166
{
165167
return true;
166168
}
167-
// 只存在一个子节点 或者左右不相等
169+
// 只存在一个子节点 或者左右不相等
168170
if(l==null || r==null || l.val != r.val)
169171
{
170172
return false;
@@ -176,6 +178,7 @@ class Solution {
176178
```
177179

178180
Python3 Code:
181+
179182
```py
180183

181184
class Solution:
@@ -191,8 +194,8 @@ class Solution:
191194

192195
**复杂度分析**
193196

194-
- 时间复杂度:$$O(N)$$,其中 N 为节点数。
195-
- 空间复杂度:递归的深度最高为节点数,因此空间复杂度是 $$O(N)$$,其中 N 为节点数。
197+
- 时间复杂度:$O(N)$,其中 N 为节点数。
198+
- 空间复杂度:递归的深度最高为节点数,因此空间复杂度是 $O(N)$,其中 N 为节点数。
196199

197200
大家对此有何看法,欢迎给我留言,我有时间都会一一查看回答。更多算法套路可以访问我的 LeetCode 题解仓库:https://github.com/azl397985856/leetcode 。 目前已经 37K star 啦。
198201
大家也可以关注我的公众号《力扣加加》带你啃下算法这块硬骨头。

problems/1011.capacity-to-ship-packages-within-d-days.md

+18-18
Original file line numberDiff line numberDiff line change
@@ -138,43 +138,43 @@ js Code:
138138
* @param {number} D
139139
* @return {number}
140140
*/
141-
var shipWithinDays = function(weights, D) {
142-
let high = weights.reduce((acc, cur) => acc + cur)
143-
let low = 0
141+
var shipWithinDays = function (weights, D) {
142+
let high = weights.reduce((acc, cur) => acc + cur);
143+
let low = 0;
144144

145-
while(low < high) {
146-
let mid = Math.floor((high + low) / 2)
145+
while (low < high) {
146+
let mid = Math.floor((high + low) / 2);
147147
if (canShip(mid)) {
148-
high = mid
148+
high = mid;
149149
} else {
150-
low = mid + 1
150+
low = mid + 1;
151151
}
152152
}
153153

154-
return low
154+
return low;
155155

156156
function canShip(opacity) {
157-
let remain = opacity
158-
let count = 1
157+
let remain = opacity;
158+
let count = 1;
159159
for (let weight of weights) {
160160
if (weight > opacity) {
161-
return false
161+
return false;
162162
}
163-
remain -= weight
163+
remain -= weight;
164164
if (remain < 0) {
165-
count++
166-
remain = opacity - weight
165+
count++;
166+
remain = opacity - weight;
167167
}
168168
if (count > D) {
169-
return false
169+
return false;
170170
}
171171
}
172-
return count <= D
172+
return count <= D;
173173
}
174174
};
175175
```
176176

177177
**复杂度分析**
178178

179-
- 时间复杂度:$$O(logN)$$
180-
- 空间复杂度:$$O(N)$$
179+
- 时间复杂度:$O(logN)$
180+
- 空间复杂度:$O(N)$

problems/1014.best-sightseeing-pair.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ class Solution:
106106

107107
**复杂度分析**
108108

109-
- 时间复杂度:$$O(N)$$
110-
- 空间复杂度:$$O(N)$$
109+
- 时间复杂度:$O(N)$
110+
- 空间复杂度:$O(N)$
111111

112112
大家对此有何看法,欢迎给我留言,我有时间都会一一查看回答。更多算法套路可以访问我的 LeetCode 题解仓库:https://github.com/azl397985856/leetcode 。 目前已经 37K star 啦。
113113
大家也可以关注我的公众号《力扣加加》带你啃下算法这块硬骨头。

problems/1019.next-greater-node-in-linked-list.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ https://leetcode-cn.com/problems/next-greater-node-in-linked-list/
4949

5050
看完题目就应该想到单调栈才行,LeetCode 上关于单调栈的题目还不少,难度都不小。但是一旦你掌握了这个算法,那么这些题目对你来说都不是问题了。
5151

52-
如果你不用单调栈,那么可以暴力$$O(N^2)$$的时间复杂度解决,只需要双层循环即可。但是这种做法应该是过不了关的。使用单调栈可以将时间复杂度降低到线性,当然需要额外的$$O(N)$$的空间复杂度。
52+
如果你不用单调栈,那么可以暴力$O(N^2)$的时间复杂度解决,只需要双层循环即可。但是这种做法应该是过不了关的。使用单调栈可以将时间复杂度降低到线性,当然需要额外的$O(N)$的空间复杂度。
5353

5454
顾名思义,单调栈即满足单调性的栈结构。与单调队列相比,其只在一端进行进出。为了描述方便,以下举例及代码以维护一个整数的单调递减栈为例。将一个元素插入单调栈时,为了维护栈的单调性,需要在保证将该元素插入到栈顶后整个栈满足单调性的前提下弹出最少的元素。
5555

@@ -107,12 +107,12 @@ class Solution:
107107

108108
其中 N 为链表的长度。
109109

110-
- 时间复杂度:$$O(N)$$
111-
- 空间复杂度:$$O(N)$$
110+
- 时间复杂度:$O(N)$
111+
- 空间复杂度:$O(N)$
112112

113113
## 扩展
114114

115-
甚至可以做到 O(1)的空间复杂度,请参考[C# O(n) time O(1) space](https://leetcode.com/problems/next-greater-node-in-linked-list/discuss/267090/C-O(n)-time-O(1)-space)
115+
甚至可以做到 O(1)的空间复杂度,请参考[C# O(n) time O(1) space](<https://leetcode.com/problems/next-greater-node-in-linked-list/discuss/267090/C-O(n)-time-O(1)-space>)
116116

117117
## 相关题目
118118

0 commit comments

Comments
 (0)