66
77总计21题,题目列表请戳 [ LeetCode Hot100 easy 列表] ( https://leetcode-cn.com/problemset/leetcode-hot-100/?difficulty=%E7%AE%80%E5%8D%95 ) 。
88
9- 全部源码可见我的GitHub [ interview-leetcode] ( https://github.com/minibear2333 /interview-leetcode/tree/master/LeetCode/all )
9+ 全部源码可见我的GitHub [ interview-leetcode] ( https://github.com/coding3min /interview-leetcode/tree/master/LeetCode/all )
1010
1111注:
1212
2020
2121题解:遍历数组,用目标值减去当前值,判断HashMap是否有值存在,如果有则创建新数组返回两者,如果没有循环遍历完返回空数组
2222
23- 时间复杂度:O\( 1\) 代码:[ golang] ( https://github.com/minibear2333 /interview-leetcode/tree/f218b102b41d5ce6b95e9b305fdc326205b4e2f9/LeetCode/all/1.两数之和.go )
23+ 时间复杂度:O\( 1\) 代码:[ golang] ( https://github.com/coding3min /interview-leetcode/tree/f218b102b41d5ce6b95e9b305fdc326205b4e2f9/LeetCode/all/1.两数之和.go )
2424
2525### 20.有效的括号\( 高频\)
2626
3030
3131注意:go语言可以用byte代表单个字符
3232
33- 代码:[ golang] ( https://github.com/minibear2333 /interview-leetcode/tree/f218b102b41d5ce6b95e9b305fdc326205b4e2f9/LeetCode/all/20.有效的括号.go )
33+ 代码:[ golang] ( https://github.com/coding3min /interview-leetcode/tree/f218b102b41d5ce6b95e9b305fdc326205b4e2f9/LeetCode/all/20.有效的括号.go )
3434
3535### 21.合并两个有序链表\( 高频\)
3636
@@ -58,7 +58,7 @@ if l1!=nil{
5858}
5959```
6060
61- 代码:[ golang] ( https://github.com/minibear2333 /interview-leetcode/tree/f218b102b41d5ce6b95e9b305fdc326205b4e2f9/LeetCode/all/21.合并两个有序链表.go )
61+ 代码:[ golang] ( https://github.com/coding3min /interview-leetcode/tree/f218b102b41d5ce6b95e9b305fdc326205b4e2f9/LeetCode/all/21.合并两个有序链表.go )
6262
6363### 53.最大子序和\( 高频\)
6464
@@ -78,15 +78,15 @@ last = max(nums[i],nums[i]+last)
7878resMax = max (resMax,last)
7979```
8080
81- 代码:[ golang] ( https://github.com/minibear2333 /interview-leetcode/tree/f218b102b41d5ce6b95e9b305fdc326205b4e2f9/LeetCode/all/53.最大子序和.go )
81+ 代码:[ golang] ( https://github.com/coding3min /interview-leetcode/tree/f218b102b41d5ce6b95e9b305fdc326205b4e2f9/LeetCode/all/53.最大子序和.go )
8282
8383### 70.爬楼梯
8484
8585题目:[ 一次可以上一阶或者二阶,如果是n阶有多少种爬法] ( https://leetcode-cn.com/problems/climbing-stairs/ )
8686
8787题解:斐波那契数列,返回结果是前两个值的和,只需要保存前两个值和当前结果,递推赋值即可
8888
89- 代码:[ golang] ( https://github.com/minibear2333 /interview-leetcode/tree/f218b102b41d5ce6b95e9b305fdc326205b4e2f9/LeetCode/all/70.爬楼梯.go )
89+ 代码:[ golang] ( https://github.com/coding3min /interview-leetcode/tree/f218b102b41d5ce6b95e9b305fdc326205b4e2f9/LeetCode/all/70.爬楼梯.go )
9090
9191### 101.对称二叉树
9292
@@ -112,15 +112,15 @@ if p==nil || q==nil{
112112}
113113```
114114
115- 代码:[ golang] ( https://github.com/minibear2333 /interview-leetcode/tree/f218b102b41d5ce6b95e9b305fdc326205b4e2f9/LeetCode/all/101.对称二叉树.go )
115+ 代码:[ golang] ( https://github.com/coding3min /interview-leetcode/tree/f218b102b41d5ce6b95e9b305fdc326205b4e2f9/LeetCode/all/101.对称二叉树.go )
116116
117117### 104.二叉树的最大深度
118118
119119题目:[ 根节点到最远叶子节点的最长路径上的节点数] ( https://leetcode-cn.com/problems/maximum-depth-of-binary-tree/description/ )
120120
121121题解:递归,前序遍历,返回值为左右节点最大深度+1,退出条件为null节点返回0,左右子树都为空返回1
122122
123- 代码:[ golang] ( https://github.com/minibear2333 /interview-leetcode/tree/f218b102b41d5ce6b95e9b305fdc326205b4e2f9/LeetCode/all/104.二叉树的最大深度.go )
123+ 代码:[ golang] ( https://github.com/coding3min /interview-leetcode/tree/f218b102b41d5ce6b95e9b305fdc326205b4e2f9/LeetCode/all/104.二叉树的最大深度.go )
124124
125125### 121.买卖股票的最佳时机\( 高频\)
126126
@@ -136,7 +136,7 @@ if v<minNum{
136136}
137137```
138138
139- 代码:[ golang] ( https://github.com/minibear2333 /interview-leetcode/tree/f218b102b41d5ce6b95e9b305fdc326205b4e2f9/LeetCode/all/121.买卖股票的最佳时机.go )
139+ 代码:[ golang] ( https://github.com/coding3min /interview-leetcode/tree/f218b102b41d5ce6b95e9b305fdc326205b4e2f9/LeetCode/all/121.买卖股票的最佳时机.go )
140140
141141### 136.只出现一次的数字
142142
@@ -148,7 +148,7 @@ if v<minNum{
148148* 方法二、每个值都异或,最终得到的就是答案
149149* 异或的性质:` a^a=0, a^0=a `
150150
151- 代码:[ golang] ( https://github.com/minibear2333 /interview-leetcode/tree/f218b102b41d5ce6b95e9b305fdc326205b4e2f9/LeetCode/all/136.只出现一次的数字.go )
151+ 代码:[ golang] ( https://github.com/coding3min /interview-leetcode/tree/f218b102b41d5ce6b95e9b305fdc326205b4e2f9/LeetCode/all/136.只出现一次的数字.go )
152152
153153### 141.环形链表\( 高频\)
154154
@@ -160,7 +160,7 @@ if v<minNum{
160160p.Next != nil && q.Next != nil && q.Next .Next != nil
161161```
162162
163- 代码:[ golang] ( https://github.com/minibear2333 /interview-leetcode/tree/f218b102b41d5ce6b95e9b305fdc326205b4e2f9/LeetCode/all/141.环形链表.go )
163+ 代码:[ golang] ( https://github.com/coding3min /interview-leetcode/tree/f218b102b41d5ce6b95e9b305fdc326205b4e2f9/LeetCode/all/141.环形链表.go )
164164
165165### 155.最小栈\( 中频\)
166166
@@ -175,7 +175,7 @@ p.Next != nil && q.Next != nil && q.Next.Next != nil
175175
176176这样出栈同同步出栈,始终最小值就是栈2的栈顶,使用了一个当前最优解的思路
177177
178- 代码:[ golang] ( https://github.com/minibear2333 /interview-leetcode/tree/f218b102b41d5ce6b95e9b305fdc326205b4e2f9/LeetCode/all/155.最小栈.go )
178+ 代码:[ golang] ( https://github.com/coding3min /interview-leetcode/tree/f218b102b41d5ce6b95e9b305fdc326205b4e2f9/LeetCode/all/155.最小栈.go )
179179
180180### 160.相交链表\( 高频\)
181181
@@ -199,7 +199,7 @@ pA:1->2->3->4->5->6->null->9->5->6->null
199199pB:9->5->6->null->1->2->3->4->5->6->null
200200```
201201
202- 代码:[ golang] ( https://github.com/minibear2333 /interview-leetcode/tree/f218b102b41d5ce6b95e9b305fdc326205b4e2f9/LeetCode/all/160.相交链表.go )
202+ 代码:[ golang] ( https://github.com/coding3min /interview-leetcode/tree/f218b102b41d5ce6b95e9b305fdc326205b4e2f9/LeetCode/all/160.相交链表.go )
203203
204204### 169.多数元素
205205
@@ -227,7 +227,7 @@ func majorityElement(nums []int) int {
227227}
228228```
229229
230- 代码:[ golang] ( https://github.com/minibear2333 /interview-leetcode/tree/f218b102b41d5ce6b95e9b305fdc326205b4e2f9/LeetCode/all/169.多数元素.go )
230+ 代码:[ golang] ( https://github.com/coding3min /interview-leetcode/tree/f218b102b41d5ce6b95e9b305fdc326205b4e2f9/LeetCode/all/169.多数元素.go )
231231
232232### 206.反转链表\( 高频\)
233233
@@ -264,7 +264,7 @@ return newHead
264264* 每次保存下一个节点,让当前节点指向上一个节点
265265* 然后向下走一位,` prev=curr; curr=next ` ,` curr ` 为空时停止,` prev ` 就是新的头节点
266266
267- 代码:[ golang] ( https://github.com/minibear2333 /interview-leetcode/tree/f218b102b41d5ce6b95e9b305fdc326205b4e2f9/LeetCode/all/206.反转链表.go )
267+ 代码:[ golang] ( https://github.com/coding3min /interview-leetcode/tree/f218b102b41d5ce6b95e9b305fdc326205b4e2f9/LeetCode/all/206.反转链表.go )
268268
269269### 226.翻转二叉树
270270
@@ -281,7 +281,7 @@ return newHead
281281
282282方法2 递归:其实子节点还是属于父节点,只要翻转左右节点位置就行了
283283
284- 自身递归,“交换”左右子树时记得备份。 代码:[ golang] ( https://github.com/minibear2333 /interview-leetcode/tree/f218b102b41d5ce6b95e9b305fdc326205b4e2f9/LeetCode/all/226.翻转二叉树.go )
284+ 自身递归,“交换”左右子树时记得备份。 代码:[ golang] ( https://github.com/coding3min /interview-leetcode/tree/f218b102b41d5ce6b95e9b305fdc326205b4e2f9/LeetCode/all/226.翻转二叉树.go )
285285
286286### 234.回文链表
287287
@@ -292,31 +292,31 @@ return newHead
292292* 把剩下的一半变成逆序,再进行比较。注意奇偶情况讨论。递归非递归都行,想起来哪个用哪个,判断完后恢复链表
293293* 如果要快就边跑边让慢指针翻转链表,结束后也不用恢复
294294
295- 代码:[ golang] ( https://github.com/minibear2333 /interview-leetcode/tree/f218b102b41d5ce6b95e9b305fdc326205b4e2f9/LeetCode/all/234.回文链表.go )
295+ 代码:[ golang] ( https://github.com/coding3min /interview-leetcode/tree/f218b102b41d5ce6b95e9b305fdc326205b4e2f9/LeetCode/all/234.回文链表.go )
296296
297297### 283.移动零
298298
299299题目:[ 把数组里的零全部移动到结尾] ( https://leetcode-cn.com/problems/move-zeroes/description/ )
300300
301301题解:两个下标,使用类似于选择插入排序的方法,不断扩充非零列,剩余的元素用0填充
302302
303- 代码:[ golang] ( https://github.com/minibear2333 /interview-leetcode/tree/f218b102b41d5ce6b95e9b305fdc326205b4e2f9/LeetCode/all/283.移动零.go )
303+ 代码:[ golang] ( https://github.com/coding3min /interview-leetcode/tree/f218b102b41d5ce6b95e9b305fdc326205b4e2f9/LeetCode/all/283.移动零.go )
304304
305305### 448.找到所有数组中消失的数字
306306
307307题目:[ 1-n的数字存储在长度为n的数组里,有的数字重复出现了,所以有的数字没有出现,找出没有出现的数字] ( https://leetcode-cn.com/problems/find-all-numbers-disappeared-in-an-array/description/ )
308308
309309题解: 法1、直接用hash表,比较简单,不过建议还是用法2可以体现水平 法2、用占位方法,遍历,出现的abs\( 数字\) -1作为下标的数字改为负,如果已经是负的就不用改了,最后再遍历一次数组把存储数字为正位置的\( 下标+1\) 存储到结果集里
310310
311- 代码:[ golang] ( https://github.com/minibear2333 /interview-leetcode/tree/f218b102b41d5ce6b95e9b305fdc326205b4e2f9/LeetCode/all/448.找到所有数组中消失的数字.go )
311+ 代码:[ golang] ( https://github.com/coding3min /interview-leetcode/tree/f218b102b41d5ce6b95e9b305fdc326205b4e2f9/LeetCode/all/448.找到所有数组中消失的数字.go )
312312
313313### 461.汉明距离
314314
315315题目:[ 求两个数字二进制位不同的有多少个] ( https://leetcode-cn.com/problems/hamming-distance/description/ )
316316
317317题解:先亦或,然后` %2=1 ` 时统计,` >>1 ` 代表` /2 ` 去掉一位
318318
319- 代码:[ golang] ( https://github.com/minibear2333 /interview-leetcode/tree/f218b102b41d5ce6b95e9b305fdc326205b4e2f9/LeetCode/all/461.汉明距离.go )
319+ 代码:[ golang] ( https://github.com/coding3min /interview-leetcode/tree/f218b102b41d5ce6b95e9b305fdc326205b4e2f9/LeetCode/all/461.汉明距离.go )
320320
321321### 543.二叉树的直径
322322
@@ -328,7 +328,7 @@ return newHead
328328* 维护一个最大值,递归返回后判断左右子树贡献的深度和,与最大值哪个大,更新最大值,这样可以保证直径是当前最大 ` max(x+y,maxRes) `
329329* 返回当前子树最大深度` return max(x,y)+1 `
330330
331- 代码:[ golang] ( https://github.com/minibear2333 /interview-leetcode/tree/f218b102b41d5ce6b95e9b305fdc326205b4e2f9/LeetCode/all/543.二叉树的直径.go )
331+ 代码:[ golang] ( https://github.com/coding3min /interview-leetcode/tree/f218b102b41d5ce6b95e9b305fdc326205b4e2f9/LeetCode/all/543.二叉树的直径.go )
332332
333333### 617.合并二叉树
334334
@@ -341,13 +341,13 @@ return newHead
341341* 处理递归函数,分别传入两棵树的左子树或右子树,赋值给当前节点左右子树
342342* 跟437 路径总和III的思想是一样的。
343343
344- 代码:[ golang] ( https://github.com/minibear2333 /interview-leetcode/tree/f218b102b41d5ce6b95e9b305fdc326205b4e2f9/LeetCode/all/617.合并二叉树.go )
344+ 代码:[ golang] ( https://github.com/coding3min /interview-leetcode/tree/f218b102b41d5ce6b95e9b305fdc326205b4e2f9/LeetCode/all/617.合并二叉树.go )
345345
346346## 最后
347347
348348如果文中有误,欢迎提pr或者issue,** 一旦合并或采纳作为贡献奖励可以联系我直接无门槛** 加入[ 技术交流群] ( https://mp.weixin.qq.com/s/ErQFjJbIsMVGjIRWbQCD1Q )
349349
350350我是小熊,关注我,知道更多不知道的技术
351351
352- ![ ] ( https://github.com/minibear2333 /interview-leetcode/tree/f218b102b41d5ce6b95e9b305fdc326205b4e2f9/LeetCode/hot100/res/2021-03-17-19-57-33.png )
352+ ![ ] ( https://github.com/coding3min /interview-leetcode/tree/f218b102b41d5ce6b95e9b305fdc326205b4e2f9/LeetCode/hot100/res/2021-03-17-19-57-33.png )
353353
0 commit comments