Skip to content

Commit b8deed9

Browse files
committed
gogoogo ! 2022.3.3
1 parent 788e492 commit b8deed9

File tree

284 files changed

+295
-74
lines changed

Some content is hidden

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

284 files changed

+295
-74
lines changed

.idea/$PRODUCT_WORKSPACE_FILE$

100644100755
File mode changed.

.idea/.gitignore

100644100755
File mode changed.

.idea/Leetcode_notes.iml

100644100755
File mode changed.

.idea/misc.xml

100644100755
File mode changed.

.idea/modules.xml

100644100755
File mode changed.

.idea/vcs.xml

100644100755
File mode changed.

Daily-record/2022.1.md

100644100755
File mode changed.

Daily-record/2022.2.md

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
## M1芯片报错
2+
3+
需要将一系列的go/goland之类的切换为arm结构安装,go1.16之后才支持m1芯片。
4+
5+
6+
7+
## mac键盘映射问题
8+
9+
将option和command互换。
10+
11+
<img src="images/image-20220224150827401.png" alt="image-20220224150827401" style="zoom:50%;" />
12+
13+
14+
15+
## M1执行go test 出现warning
16+
17+
该缺陷已修复,报错原因为:`kIOMasterPortDefault`已经被替换为`kIOMainPortDefault`,手动替换即可。
18+
19+
已经更新到0.0.2版本,[Deprecation warnings when building on macOS 12.0](https://github.com/karalabe/usb/issues/25),利用go get 指定版本,并删除../../../../../pkg/mod/github.com/karalabe/usb目录下的老版本。但go tool似乎会指定老版本并下载。
20+
21+
```shell
22+
# github.com/karalabe/usb
23+
In file included from ../../../../../pkg/mod/github.com/karalabe/[email protected]/libs.go:50:
24+
../../../../../pkg/mod/github.com/karalabe/[email protected]/libusb/libusb/os/darwin_usb.c:253:39: warning: 'kIOMasterPortDefault' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
25+
/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/System/Library/Frameworks/IOKit.framework/Headers/IOKitLib.h:123:19: note: 'kIOMasterPortDefault' has been explicitly marked deprecated here
26+
In file included from ../../../../../pkg/mod/github.com/karalabe/[email protected]/libs.go:50:
27+
../../../../../pkg/mod/github.com/karalabe/[email protected]/libusb/libusb/os/darwin_usb.c:390:26: warning: 'kIOMasterPortDefault' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
28+
/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/System/Library/Frameworks/IOKit.framework/Headers/IOKitLib.h:123:19: note: 'kIOMasterPortDefault' has been explicitly marked deprecated here
29+
In file included from ../../../../../pkg/mod/github.com/karalabe/[email protected]/libs.go:50:
30+
../../../../../pkg/mod/github.com/karalabe/[email protected]/libusb/libusb/os/darwin_usb.c:441:60: warning: 'kIOMasterPortDefault' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
31+
/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/System/Library/Frameworks/IOKit.framework/Headers/IOKitLib.h:123:19: note: 'kIOMasterPortDefault' has been explicitly marked deprecated here
32+
In file included from ../../../../../pkg/mod/github.com/karalabe/[email protected]/libs.go:51:
33+
../../../../../pkg/mod/github.com/karalabe/[email protected]/hidapi/mac/hid.c:693:34: warning: 'kIOMasterPortDefault' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
34+
/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/System/Library/Frameworks/IOKit.framework/Headers/IOKitLib.h:123:19: note: 'kIOMasterPortDefault' has been explicitly marked deprecated here
35+
36+
```
37+
38+
39+
40+
## proto编译报错
41+
42+
```shell
43+
$ protoc -I=. \
44+
-I/Users/liruoxin/goproject/src \
45+
--gogofaster_out=:. \
46+
receipt.proto
47+
48+
protoc-gen-gogofaster: program not found or is not executable
49+
Please specify a program using absolute path or make sure the program is available in your PATH system variable
50+
--gogofaster_out: protoc-gen-gogofaster: Plugin failed with status code
51+
(base)
52+
```
53+
54+
55+
56+
拉一下这个包`go get -u github.com/gogo/protobuf/protoc-gen-gogofaster`,默认安装到$GOBIN目录下,记得将GOBIN目录添加到PATH目录`export PATH=$GOBIN:$PATH`(或者将该二进制文件copy到/usr/local/bin)
Loading

README.md

100644100755
File mode changed.

_config.yml

100644100755
File mode changed.

daily-problem/1. 两数之和.md

100644100755
+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
**动画图解:**
2424

25-
![leetcode1](image/leetcode1.gif)
25+
![leetcode1](images/leetcode1.gif)
2626

2727
```java
2828
class Solution {

daily-problem/1002. 查找常用字符.md

100644100755
+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
3. 对每次的hash 和 hashOtherStr 取最小值,这是本题关键所在,此时取最小值,就是一个字符在所有字符串里出现的最小次数了。
3838
4. 此时hash里统计着字符在所有字符串里出现的最小次数,那么把hash转正题目要求的输出格式就可以了。
3939

40-
![](image/1602641686-ZjKqgU-1002.查找常用字符.png)
40+
![](images/1602641686-ZjKqgU-1002.查找常用字符.png)
4141

4242

4343

daily-problem/1018. 可被 5 整除的二进制前缀.md

100644100755
File mode changed.

daily-problem/103. 二叉树的锯齿形层序遍历.md

100644100755
File mode changed.

daily-problem/1030. 距离顺序排列矩阵单元格.md

100644100755
File mode changed.

daily-problem/106.md

100644100755
File mode changed.

daily-problem/1143. 最长公共子序列.md

100644100755
+5-5
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
3. **找状态转移方程**
6161
这是动态规划最难的一步,我们来通过案例推导出来。求 s1 和 s2 的最长公共子序列,不妨称这个子序列为 lcs。那么对于 s1 和 s2 中的每个字符,有什么选择?很简单,两种选择,要么在 lcs 中,要么不在。
6262

63-
![img](image/b54067c447c5b4d68821b41f0ab5e9f531c79cf25de4b2583ccc41e97e1e611d.png)
63+
![img](images/b54067c447c5b4d68821b41f0ab5e9f531c79cf25de4b2583ccc41e97e1e611d.png)
6464

6565
这个「在」和「不在」就是选择,关键是,应该如何选择呢?如果某个字符应该在 lcs 中,那么这个字符肯定同时存在于 s1 和 s2 中,所以本题的思路是这样:
6666

@@ -70,7 +70,7 @@
7070

7171
动态数组如下,其中d[2][4] 的含义就是:对于 `"ac"``"babc"`,它们的 LCS 长度是 2。我们最终想得到的答案应该是 `dp[3][6]`。:
7272

73-
![img](image/8c371d5bbba8c503329992ac36464f04d11e6617a550bfad2cfcb4e0e7965bf9.png)
73+
![img](images/8c371d5bbba8c503329992ac36464f04d11e6617a550bfad2cfcb4e0e7965bf9.png)
7474

7575

7676

@@ -113,7 +113,7 @@ class Solution {
113113

114114
下面是求解时的动态规划表,可以看出 X 和 Y 的最长公共子序列的长度为4:
115115

116-
![img](image/20141127164703086.png)
116+
![img](images/20141127164703086.png)
117117

118118
输出一个最长公共子序列并不难,难点在于输出所有的最长公共子序列,因为 LCS 通常不唯一。总之,我们需要在动态规划表上进行回溯 —— 从`dp[m][n]`,即右下角的格子,开始进行判断:
119119

@@ -123,7 +123,7 @@ class Solution {
123123

124124
**如果出现`dp[i-1][j]`等于`dp[i][j-1]`的情况,说明最长公共子序列有多个,故两边都要进行回溯(这里用到递归)。**
125125

126-
![img](image/20141129154238387.png)
126+
![img](images/20141129154238387.png)
127127

128128
从上图的红色路径显示,str1 和 str2 的最长公共子序列有 3 个,分别为 “BDAB”、“BCAB”、“BCBA”。
129129

@@ -281,7 +281,7 @@ class Solution {
281281

282282
因为下一行的取值只与上一行有关,所以可以将二维数组优化成一维数组,不过要注意第二层必须要**逆序遍历**
283283

284-
![image-20201014165747416](image/image-20201014165747416.png)
284+
![images-20201014165747416](images/images-20201014165747416.png)
285285

286286
```java
287287
class Solution {

daily-problem/116. 填充每个节点的下一个右侧节点指针.md

100644100755
+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct Node {
2020

2121
**示例:**
2222

23-
![img](image/116_sample.png)
23+
![img](images/116_sample.png)
2424

2525
```
2626
输入:{"$id":"1","left":{"$id":"2","left":{"$id":"3","left":null,"next":null,"right":null,"val":4},"next":null,"right":{"$id":"4","left":null,"next":null,"right":null,"val":5},"val":2},"next":null,"right":{"$id":"5","left":{"$id":"6","left":null,"next":null,"right":null,"val":6},"next":null,"right":{"$id":"7","left":null,"next":null,"right":null,"val":7},"val":3},"val":1}
@@ -41,9 +41,9 @@ struct Node {
4141

4242
1.双指针法,参照[leetcode117-填充每个节点的下一个右侧节点指针 II](https://leetcode-cn.com/problems/populating-next-right-pointers-in-each-node-ii/)](.\leecode117.md)
4343

44-
![image.png](image/1602724262-gxSbdy-image.png)
44+
![images.png](images/1602724262-gxSbdy-images.png)
4545

46-
![image.png](image/1602724301-qvoabL-image.png)
46+
![images.png](images/1602724301-qvoabL-images.png)
4747

4848
**代码演示:**
4949

daily-problem/117.md

100644100755
+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct Node {
2424

2525
示例:
2626

27-
![img](image/117_sample.png)
27+
![img](images/117_sample.png)
2828

2929
```
3030
输入:root = [1,2,3,4,5,null,7]

daily-problem/1207. 独一无二的出现次数.md

100644100755
File mode changed.

daily-problem/134. 加油站.md

100644100755
+5-5
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ gas = [1,2,3,4,5]
5858
cost = [3,4,5,1,2]
5959
下图绿色折线图即总油量剩余值spare,不同起点对应的绿色折线图位置不同,若要满足题目的要求:跑完全程再回到起点,总油量剩余值的任意部分**都需要在X轴以上**,且跑到终点时:**总剩余汽油量 >= 0**
6060

61-
![index0](image/index0.png)
61+
![index0](images/index0.png)
6262

63-
![index1](image/index1.png)
63+
![index1](images/index1.png)
6464

65-
![index2](image/index2.png)
65+
![index2](images/index2.png)
6666

67-
![index3](image/index3.png)
67+
![index3](images/index3.png)
6868

69-
![index4](image/index4.png)
69+
![index4](images/index4.png)
7070

7171

7272

daily-problem/135. 分发糖果.md

100644100755
+8-8
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
最终,取以上 2 轮遍历 ascend 和 descend 对应学生糖果数的 最大值 ,这样则同时满足左规则和右规则 ,即得到每个同学的最少糖果数量。
3838

39-
**动画演示:**![leetcode135](image/leetcode135.gif)
39+
**动画演示:**![leetcode135](images/leetcode135.gif)
4040

4141
**代码演示(Golang)**
4242

@@ -139,32 +139,32 @@ func max(a,b int) int {
139139

140140
1. `ratings[i - 1] == ratings[i]`,那么我们只需要 1 糖果
141141

142-
![1563430973450.png](image/b8a0cf64abf988bef3da02801e81cf1580a9a18b0e96d6ba6b47b2c5b06f8bae-1563430973450.png)
142+
![1563430973450.png](images/b8a0cf64abf988bef3da02801e81cf1580a9a18b0e96d6ba6b47b2c5b06f8bae-1563430973450.png)
143143

144144
2. `ratings[i - 1] < ratings[i]`,那么我们只需要比前一个多一块糖果
145145

146-
![1563431091961.png](image/669cf8f3db923ebaf4aac369f579c2348c245862e7f649260c7c50146aa99dd4-1563431091961.png)
146+
![1563431091961.png](images/669cf8f3db923ebaf4aac369f579c2348c245862e7f649260c7c50146aa99dd4-1563431091961.png)
147147

148148
3. `ratings[i - 1] > ratings[i]`,那么我们不知道如何判断了,比如:
149149

150-
![1563431300625.png](image/ac7842324de8da76899c631dee1c0c84cca355d8a09d218a9be887f1c4306283-1563431300625.png)
150+
![1563431300625.png](images/ac7842324de8da76899c631dee1c0c84cca355d8a09d218a9be887f1c4306283-1563431300625.png)
151151

152152

153153
但是,如果知道**递减**的个数,我们就能判断最少的糖果了
154154

155-
![1563431573161.png](image/169784d31f20cca02a4d82c0946ce848ca369d7fd5a5fee5984ea92e96a7c562-1563431573161.png)
155+
![1563431573161.png](images/169784d31f20cca02a4d82c0946ce848ca369d7fd5a5fee5984ea92e96a7c562-1563431573161.png)
156156

157157
所以我们保证,递减序列,是从 1 开始加的(方向加),再举个例子:
158158

159-
![1563431873123.png](image/0b278240d44a74e0e518bda7749d38b65276b63dce07dbecdf3c0e419db2b80b-1563431873123.png)
159+
![1563431873123.png](images/0b278240d44a74e0e518bda7749d38b65276b63dce07dbecdf3c0e419db2b80b-1563431873123.png)
160160

161161
如何判读 ? 的糖果多少,我们发现 ratings是3 - 2 递减的,递减序列个数 为`des_num`,我们反向加,
162162

163-
有公差为 1 的求和公式首项尾项项数![image-20201224211530900](image/image-20201224211530900.png),所以我们先假设 rating 在等于 4 时候也是满足等差的,所以,有![image-20201224211609606](image/image-2020122421160966.png)糖果,所以 ratings 是 3 - 2 对于的糖果说 2 - 1
163+
有公差为 1 的求和公式首项尾项项数![images-20201224211530900](images/images-20201224211530900.png),所以我们先假设 rating 在等于 4 时候也是满足等差的,所以,有![images-20201224211609606](images/images-2020122421160966.png)糖果,所以 ratings 是 3 - 2 对于的糖果说 2 - 1
164164

165165
但是还有一种可能, 如下图所示:
166166

167-
![1563436200915.png](image/a82f697e7be2aff71e3c47201f6cc89968b5a87eaa454d35fb83d6b33835f481-1563436200915.png)
167+
![1563436200915.png](images/a82f697e7be2aff71e3c47201f6cc89968b5a87eaa454d35fb83d6b33835f481-1563436200915.png)
168168

169169
**代码演示(Golang)**
170170

daily-problem/1365. 有多少小于当前数字的数字.md

100644100755
File mode changed.

daily-problem/1370. 上升下降字符串.md

100644100755
File mode changed.

daily-problem/141. 环形链表.md

100644100755
+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
你能用 O(1)(即,常量)内存解决此问题吗?
1212

13-
![circularlinkedlist](image/circularlinkedlist.png)
13+
![circularlinkedlist](images/circularlinkedlist.png)
1414

1515
```
1616
示例 1:
@@ -50,7 +50,7 @@ pos 为 -1 或者链表中的一个有效索引 。
5050

5151
**动画图解:**
5252

53-
![leetcode141](image/leetcode141.gif)
53+
![leetcode141](images/leetcode141.gif)
5454

5555

5656

@@ -101,7 +101,7 @@ public class Solution {
101101

102102
#### 解题思路:
103103

104-
![image-20201010223125414](image/image-20201010223125414.png)
104+
![images-20201010223125414](images/images-20201010223125414.png)
105105

106106
**代码演示:**
107107

daily-problem/143. 重排链表.md

100644100755
File mode changed.

daily-problem/164. 最大间距.md

100644100755
+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
题目要求**在线性时间复杂度和空间复杂度的条件下解决此问题**。但传统的基于比较的排序算法(快速排序、归并排序等)均需要 O*(*N*log*N) 的时间复杂度。我们必须使用其他的排序算法。例如基数排序和桶排序。
2929

30-
![img](file:///home/zebra/%E6%96%87%E6%A1%A3/%E7%AC%94%E8%AE%B0/Leetcode_notes/%E7%BB%8F%E5%85%B8%E7%AE%97%E6%B3%95%E6%80%BB%E7%BB%93/image/849589-20180402133438219-1946132192.png?lastModify=1606396763)
30+
![img](file:///home/zebra/%E6%96%87%E6%A1%A3/%E7%AC%94%E8%AE%B0/Leetcode_notes/%E7%BB%8F%E5%85%B8%E7%AE%97%E6%B3%95%E6%80%BB%E7%BB%93/images/849589-20180402133438219-1946132192.png?lastModify=1606396763)
3131

3232
**方法一:基数排序**
3333

@@ -43,7 +43,7 @@
4343

4444
**动图演示**
4545

46-
![img](image/849589-20171015232453668-1397662527.gif)
46+
![img](images/849589-20171015232453668-1397662527.gif)
4747

4848

4949

@@ -157,7 +157,7 @@ class Solution {
157157

158158
**图片演示**
159159

160-
![img](image/demo_js_algorithmSort_bucketSort_1.png)
160+
![img](images/demo_js_algorithmSort_bucketSort_1.png)
161161

162162

163163

daily-problem/18. 四数之和.md

100644100755
+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
**动画图解:**
3636

37-
![leetcode18](image/leetcode18.gif)
37+
![leetcode18](images/leetcode18.gif)
3838

3939

4040

daily-problem/189. 旋转数组.md

100644100755
+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
1. 先将所有元素翻转,这样尾部的`k mod n`个元素就被移至数组头部
3434
2. 然后我们再翻转`[0,k mod n−1] `区间的元素和`[k mod n,n−1] `区间的元素即能得到最后的答案。
3535

36-
![image.png](image/1610072480-yiAYFw-image.png)
36+
![images.png](images/1610072480-yiAYFw-images.png)
3737

3838
**代码演示(Golang)**
3939

daily-problem/1984. 学生分数的最小差值.md

100644100755
File mode changed.

daily-problem/2. 两数相加.md

100644100755
+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
**动画图解:**
2626

27-
![leetcode2](./image/leetcode2.gif)
27+
![leetcode2](./images/leetcode2.gif)
2828

2929

3030

daily-problem/204. 计数质数.md

100644100755
+4-4
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,11 @@ class Solution {
113113
- 质数数组中后面质数都比该质数大。该质数 * >它的质数 = 合数后面一定会遇到
114114
- 所以当前数能被质数数组中的某质数整除,直接终止循环即可。过程如图
115115

116-
![线性筛运行过程图解2-1](image/1606979779-vnbjgf-image.png)
116+
![线性筛运行过程图解2-1](images/1606979779-vnbjgf-images.png)
117117

118-
![线性筛运行过程图解2-2](image/1606979804-RounQm-image.png)
118+
![线性筛运行过程图解2-2](images/1606979804-RounQm-images.png)
119119

120-
**核心点在于**:如果 x 可以被 primes~i~整除,那么对于合数y=x*primes~i+1~而言,它一定在后面遍历到![image-20201203210634942](image/image-20201203210634942.png)这个数的时候会被标记,其他同理,这保证了每个合数只会被其「最小的质因数」筛去,即每个合数被标记一次。
120+
**核心点在于**:如果 x 可以被 primes~i~整除,那么对于合数y=x*primes~i+1~而言,它一定在后面遍历到![images-20201203210634942](images/images-20201203210634942.png)这个数的时候会被标记,其他同理,这保证了每个合数只会被其「最小的质因数」筛去,即每个合数被标记一次。
121121

122122
**代码演示**
123123

@@ -158,7 +158,7 @@ class Solution {
158158
- 奇数 乘以 偶数 一定是 偶数。只用奇数 乘以 奇数,确保在奇数范围内标记
159159
- 用上面的两条优化埃氏筛解法,过程如图:
160160

161-
![奇数筛运行过程](image/1606981107-NsNHHv-image.png)
161+
![奇数筛运行过程](images/1606981107-NsNHHv-images.png)
162162

163163
**代码演示(Go)**
164164

daily-problem/222. 完全二叉树的节点个数.md

100644100755
+3-3
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@
2222

2323
假如我们有树如下:
2424

25-
![图片.png](image/33b851025e1cb182cecdc6fa55ef9e88ced778ae483eecc69f978b02187182e9-图片.png)
25+
![图片.png](images/33b851025e1cb182cecdc6fa55ef9e88ced778ae483eecc69f978b02187182e9-图片.png)
2626

2727
我们看到根节点的左右子树高度都为3,那么说明左子树是一颗满二叉树。因为节点已经填充到右子树了,左子树必定已经填满了。所以左子树的节点总数我们可以直接得到,是2<sup>left</sup> - 1,加上当前这个root节点,则正好是2<sup>3</sup>,即 8。然后只需要再对右子树进行递归统计即可。
2828

29-
![图片.png](image/3011b154048a0943a576bb2f3bcbdab489aff74ee305287d653486dac07522de-图片.png)
29+
![图片.png](images/3011b154048a0943a576bb2f3bcbdab489aff74ee305287d653486dac07522de-图片.png)
3030

3131
那假如我们的树是这样:
3232

33-
![图片.png](image/00a6c9c3be1921a8180c82b4d5ff4127166ea06430f95fb75590376663d36016-图片.png)
33+
![图片.png](images/00a6c9c3be1921a8180c82b4d5ff4127166ea06430f95fb75590376663d36016-图片.png)
3434

3535
我们看到左子树高度为3,右子树高度为2。说明此时最后一层不满,但倒数第二层已经满了,可以直接得到右子树的节点个数。同理,右子树节点+root节点,总数为2<sup>right</sup>,即2<sup>2</sup>。再对左子树进行递归查找。
3636

daily-problem/235.md renamed to daily-problem/235. 二叉搜索树的最近公共祖先.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
例如,给定如下二叉搜索树: root = [6,2,8,0,4,7,9,null,null,3,5]
88

9-
![binarytree](image/binarytree.png)
9+
![binarytree](images/binarytree.png)
1010

1111
```
1212
示例 1:

daily-problem/236.md renamed to daily-problem/236. 二叉树的最近公共祖先.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
例如,给定如下二叉树: root = [3,5,1,6,2,0,8,null,null,7,4]
88

9-
![](image/binarysearchtree_improved.png)
9+
![](images/binarysearchtree_improved.png)
1010

1111

1212

@@ -54,7 +54,7 @@ p、q 为不同节点且均存在于给定的二叉树中
5454

5555
**动画图解:**
5656

57-
![](image/leetcode236.gif)
57+
![](images/leetcode236.gif)
5858

5959
```java
6060
class Solution {

0 commit comments

Comments
 (0)