Skip to content

Commit 46faa66

Browse files
committed
Merge pull request halfrost#60 from halfrost/code_quality_improvement
optimization code quality level from A to A+
2 parents 7b73077 + 96c36de commit 46faa66

File tree

543 files changed

+2461
-2410
lines changed

Some content is hidden

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

543 files changed

+2461
-2410
lines changed

.vscode/settings.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"go.formatTool": "gofmt",
3+
"go.formatFlags": [
4+
"-s"
5+
],
6+
"[go]": {
7+
"editor.insertSpaces": false,
8+
"editor.formatOnSave": true,
9+
"editor.codeActionsOnSave": {
10+
"source.organizeImports": true
11+
}
12+
}
13+
}

README.md

+26-20
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,26 @@
88
</p>
99

1010
<p align='center'>
11+
<a href="https://github.com/halfrost/LeetCode-Go/releases/" rel="nofollow"><img alt="GitHub All Releases" src="https://img.shields.io/github/downloads/halfrost/LeetCode-Go/total?label=PDF%20downloads"></a>
12+
<img src="https://github.com/halfrost/LeetCode-Go/workflows/Deploy%20leetcode-cookbook/badge.svg?branch=master">
13+
<img src="https://travis-ci.org/halfrost/LeetCode-Go.svg?branch=master">
14+
<img src="https://goreportcard.com/badge/github.com/halfrost/LeetCode-Go">
15+
<img src="https://img.shields.io/badge/runtime%20beats-100%25-success">
16+
<img alt="GitHub go.mod Go version" src="https://img.shields.io/github/go-mod/go-version/halfrost/LeetCode-Go?color=26C2F0">
17+
<img src="https://visitor-badge.laobi.icu/badge?page_id=halfrost.LeetCode-Go">
18+
</p>
19+
20+
<p align='center'>
21+
<a href="https://github.com/halfrost/LeetCode-Go/blob/master/LICENSE"><img alt="GitHub" src="https://img.shields.io/github/license/halfrost/LeetCode-Go?label=License"></a>
22+
<img src="https://img.shields.io/badge/License-CC-000000.svg">
1123
<a href="https://leetcode.com/halfrost/"><img src="https://img.shields.io/badge/@halfrost-8751-yellow.svg">
12-
<img src="https://img.shields.io/badge/language-Golang-abcdef.svg">
24+
<img src="https://img.shields.io/badge/language-Golang-26C2F0.svg">
1325
<a href="https://halfrost.com"><img src="https://img.shields.io/badge/Blog-Halfrost--Field-80d4f9.svg?style=flat"></a>
1426
<a href="http://weibo.com/halfrost"><img src="https://img.shields.io/badge/[email protected]?style=flat&colorA=f4292e"></a>
15-
<a href="https://twitter.com/halffrost"><img src="https://img.shields.io/badge/[email protected]?style=flat&colorA=009df2"></a>
16-
<a href="http://www.jianshu.com/u/12201cdd5d7a"><img src="https://img.shields.io/badge/%E7%AE%80%E4%B9%A6-@%E4%B8%80%E7%BC%95%E6%AE%87%E6%B5%81%E5%8C%96%E9%9A%90%E5%8D%8A%E8%BE%B9%E5%86%B0%E9%9C%9C-b561fe.svg?style=flat&colorA=ed6f59"></a>
17-
<a href="https://juejin.im/user/5692e1e000b09aa2e8dcd422"><img src="https://img.shields.io/badge/%E6%8E%98%E9%87%91-@%E4%B8%80%E7%BC%95%E6%AE%87%E6%B5%81%E5%8C%96%E9%9A%90%E5%8D%8A%E8%BE%B9%E5%86%B0%E9%9C%9C-fd6f32.svg?style=flat&colorA=1970fe"></a>
18-
<a href="https://www.zhihu.com/people/halfrost/activities"><img src="https://img.shields.io/badge/%E7%9F%A5%E4%B9%[email protected]?style=flat&colorA=0083ea"></a>
19-
<img src="https://img.shields.io/badge/PR-welcome%20!-brightgreen.svg?colorA=a0cd34">
20-
<a href=""><img src="https://img.shields.io/badge/license-CC-000000.svg"></a>
27+
<a href="https://twitter.com/halffrost"><img src="https://img.shields.io/badge/[email protected]?style=flat&colorA=009df2"></a>
28+
<a href="https://www.zhihu.com/people/halfrost/activities"><img src="https://img.shields.io/badge/%E7%9F%A5%E4%B9%[email protected]?style=flat&colorA=0083ea"></a>
2129
<img src="https://img.shields.io/badge/made%20with-=1-blue.svg">
22-
<img src="https://visitor-badge.laobi.icu/badge?page_id=halfrost.LeetCode-Go">
23-
<img src="https://github.com/halfrost/LeetCode-Go/workflows/Deploy%20leetcode-cookbook/badge.svg?branch=master">
24-
<img src="https://travis-ci.org/halfrost/LeetCode-Go.svg?branch=master">
30+
<a href="https://github.com/halfrost/LeetCode-Go/pulls"><img src="https://img.shields.io/badge/PR-Welcome-brightgreen.svg"></a>
2531
</p>
2632

2733
支持 Progressive Web Apps 和 Dark Mode 的题解电子书《LeetCode Cookbook》 <a href="https://books.halfrost.com/leetcode/" rel="nofollow">Online Reading</a>
@@ -54,23 +60,23 @@
5460

5561
* [Array](#array)
5662
* [String](#string)
57-
* [Two Pointers](#two-pointers)
58-
* [Linked List](#linked-list)
59-
* [Stack ✅](#stack)
63+
* [Two Pointers](#two-pointers)
64+
* [Linked List](#linked-list)
65+
* [✅ Stack](#stack)
6066
* [Tree](#tree)
6167
* [Dynamic programming](#dynamic-programming)
62-
* [Backtracking ✅](#backtracking)
68+
* [✅ Backtracking](#backtracking)
6369
* [Depth First Search](#depth-first-search)
6470
* [Breadth First Search](#breadth-first-search)
6571
* [Binary Search](#binary-search)
6672
* [Math](#math)
6773
* [Hash Table](#hash-table)
68-
* [Sort ✅](#sort)
69-
* [Bit Manipulation](#bit-manipulation)
70-
* [Union Find](#union-find)
71-
* [Sliding Window](#sliding-window)
72-
* [Segment Tree](#segment-tree)
73-
* [Binary Indexed Tree](#binary-indexed-tree)
74+
* [✅ Sort](#sort)
75+
* [Bit Manipulation](#bit-manipulation)
76+
* [Union Find](#union-find)
77+
* [Sliding Window](#sliding-window)
78+
* [Segment Tree](#segment-tree)
79+
* [Binary Indexed Tree](#binary-indexed-tree)
7480

7581
| 数据结构 | 变种 | 相关题目 | 讲解文章 |
7682
|:-------:|:-------|:------|:------|

go.mod

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module LeetCode-Go
2+
3+
go 1.14

leetcode/0001.Two-Sum/1. Two Sum_test.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,30 @@ type ans1 struct {
2626
func Test_Problem1(t *testing.T) {
2727

2828
qs := []question1{
29-
30-
question1{
29+
{
3130
para1{[]int{3, 2, 4}, 6},
3231
ans1{[]int{1, 2}},
3332
},
3433

35-
question1{
34+
{
3635
para1{[]int{3, 2, 4}, 5},
3736
ans1{[]int{0, 1}},
3837
},
3938

40-
question1{
39+
{
4140
para1{[]int{0, 8, 7, 3, 3, 4, 2}, 11},
4241
ans1{[]int{1, 3}},
4342
},
4443

45-
question1{
44+
{
4645
para1{[]int{0, 1}, 1},
4746
ans1{[]int{0, 1}},
4847
},
4948

50-
question1{
49+
{
5150
para1{[]int{0, 3}, 5},
5251
ans1{[]int{}},
5352
},
54-
5553
// 如需多个测试,可以复制上方元素。
5654
}
5755

leetcode/0002.Add-Two-Numbers/2. Add Two Numbers_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -29,42 +29,42 @@ func Test_Problem2(t *testing.T) {
2929

3030
qs := []question2{
3131

32-
question2{
32+
{
3333
para2{[]int{}, []int{}},
3434
ans2{[]int{}},
3535
},
3636

37-
question2{
37+
{
3838
para2{[]int{1}, []int{1}},
3939
ans2{[]int{2}},
4040
},
4141

42-
question2{
42+
{
4343
para2{[]int{1, 2, 3, 4}, []int{1, 2, 3, 4}},
4444
ans2{[]int{2, 4, 6, 8}},
4545
},
4646

47-
question2{
47+
{
4848
para2{[]int{1, 2, 3, 4, 5}, []int{1, 2, 3, 4, 5}},
4949
ans2{[]int{2, 4, 6, 8, 0, 1}},
5050
},
5151

52-
question2{
52+
{
5353
para2{[]int{1}, []int{9, 9, 9, 9, 9}},
5454
ans2{[]int{0, 0, 0, 0, 0, 1}},
5555
},
5656

57-
question2{
57+
{
5858
para2{[]int{9, 9, 9, 9, 9}, []int{1}},
5959
ans2{[]int{0, 0, 0, 0, 0, 1}},
6060
},
6161

62-
question2{
62+
{
6363
para2{[]int{2, 4, 3}, []int{5, 6, 4}},
6464
ans2{[]int{7, 0, 8}},
6565
},
6666

67-
question2{
67+
{
6868
para2{[]int{1, 8, 3}, []int{7, 1}},
6969
ans2{[]int{8, 9, 3}},
7070
},

leetcode/0003.Longest-Substring-Without-Repeating-Characters/3. Longest Substring Without Repeating Characters_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,22 @@ func Test_Problem3(t *testing.T) {
2626

2727
qs := []question3{
2828

29-
question3{
29+
{
3030
para3{"abcabcbb"},
3131
ans3{3},
3232
},
3333

34-
question3{
34+
{
3535
para3{"bbbbb"},
3636
ans3{1},
3737
},
3838

39-
question3{
39+
{
4040
para3{"pwwkew"},
4141
ans3{3},
4242
},
4343

44-
question3{
44+
{
4545
para3{""},
4646
ans3{0},
4747
},

leetcode/0004.Median-of-Two-Sorted-Arrays/4. Median of Two Sorted Arrays_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ func Test_Problem4(t *testing.T) {
2727

2828
qs := []question4{
2929

30-
question4{
30+
{
3131
para4{[]int{1, 3}, []int{2}},
3232
ans4{2.0},
3333
},
3434

35-
question4{
35+
{
3636
para4{[]int{1, 2}, []int{3, 4}},
3737
ans4{2.5},
3838
},

leetcode/0007.Reverse-Integer/7. Reverse Integer_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,22 @@ func Test_Problem7(t *testing.T) {
2626

2727
qs := []question7{
2828

29-
question7{
29+
{
3030
para7{321},
3131
ans7{123},
3232
},
3333

34-
question7{
34+
{
3535
para7{-123},
3636
ans7{-321},
3737
},
3838

39-
question7{
39+
{
4040
para7{120},
4141
ans7{21},
4242
},
4343

44-
question7{
44+
{
4545
para7{1534236469},
4646
ans7{0},
4747
},

leetcode/0009.Palindrome-Number/9. Palindrome Number_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -26,37 +26,37 @@ func Test_Problem9(t *testing.T) {
2626

2727
qs := []question9{
2828

29-
question9{
29+
{
3030
para9{121},
3131
ans9{true},
3232
},
3333

34-
question9{
34+
{
3535
para9{-121},
3636
ans9{false},
3737
},
3838

39-
question9{
39+
{
4040
para9{10},
4141
ans9{false},
4242
},
4343

44-
question9{
44+
{
4545
para9{321},
4646
ans9{false},
4747
},
4848

49-
question9{
49+
{
5050
para9{-123},
5151
ans9{false},
5252
},
5353

54-
question9{
54+
{
5555
para9{120},
5656
ans9{false},
5757
},
5858

59-
question9{
59+
{
6060
para9{1534236469},
6161
ans9{false},
6262
},

leetcode/0011.Container-With-Most-Water/11. Container With Most Water_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ func Test_Problem11(t *testing.T) {
2626

2727
qs := []question11{
2828

29-
question11{
29+
{
3030
para11{[]int{1, 8, 6, 2, 5, 4, 8, 3, 7}},
3131
ans11{49},
3232
},
3333

34-
question11{
34+
{
3535
para11{[]int{1, 1}},
3636
ans11{1},
3737
},

leetcode/0013.Roman-to-Integer/13. Roman to Integer_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,32 @@ func Test_Problem13(t *testing.T) {
2626

2727
qs := []question13{
2828

29-
question13{
29+
{
3030
para13{"III"},
3131
ans13{3},
3232
},
3333

34-
question13{
34+
{
3535
para13{"IV"},
3636
ans13{4},
3737
},
3838

39-
question13{
39+
{
4040
para13{"IX"},
4141
ans13{9},
4242
},
4343

44-
question13{
44+
{
4545
para13{"LVIII"},
4646
ans13{58},
4747
},
4848

49-
question13{
49+
{
5050
para13{"MCMXCIV"},
5151
ans13{1994},
5252
},
5353

54-
question13{
54+
{
5555
para13{"MCMXICIVI"},
5656
ans13{2014},
5757
},

leetcode/0015.3Sum/15. 3Sum_test.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,26 @@ func Test_Problem15(t *testing.T) {
2626

2727
qs := []question15{
2828

29-
question15{
29+
{
3030
para15{[]int{0, 0, 0}},
31-
ans15{[][]int{[]int{0, 0, 0}}},
31+
ans15{[][]int{{0, 0, 0}}},
3232
},
3333

34-
question15{
34+
{
3535
para15{[]int{-1, 0, 1, 2, -1, -4}},
36-
ans15{[][]int{[]int{-1, 0, 1}, []int{-1, -1, 2}}},
36+
ans15{[][]int{{-1, 0, 1}, {-1, -1, 2}}},
3737
},
3838

39-
question15{
39+
{
4040
para15{[]int{-4, -2, -2, -2, 0, 1, 2, 2, 2, 3, 3, 4, 4, 6, 6}},
41-
ans15{[][]int{[]int{-4, -2, 6}, []int{-4, 0, 4}, []int{-4, 1, 3}, []int{-4, 2, 2}, []int{-2, -2, 4}, []int{-2, 0, 2}}},
41+
ans15{[][]int{{-4, -2, 6}, {-4, 0, 4}, {-4, 1, 3}, {-4, 2, 2}, {-2, -2, 4}, {-2, 0, 2}}},
4242
},
4343

44-
question15{
44+
{
4545
para15{[]int{5, -7, 3, -3, 5, -10, 4, 8, -3, -8, -3, -3, -1, -8, 6, 4, -4, 7, 2, -5, -2, -7, -3, 7, 2, 4, -6, 5}},
46-
ans15{[][]int{[]int{-10, 2, 8}, []int{-10, 3, 7}, []int{-10, 4, 6}, []int{-10, 5, 5}, []int{-8, 2, 6}, []int{-8, 3, 5}, []int{-8, 4, 4}, []int{-7, -1, 8},
47-
[]int{-7, 2, 5}, []int{-7, 3, 4}, []int{-6, -2, 8}, []int{-6, -1, 7}, []int{-6, 2, 4}, []int{-5, -3, 8}, []int{-5, -2, 7}, []int{-5, -1, 6}, []int{-5, 2, 3},
48-
[]int{-4, -3, 7}, []int{-4, -2, 6}, []int{-4, -1, 5}, []int{-4, 2, 2}, []int{-3, -3, 6}, []int{-3, -2, 5}, []int{-3, -1, 4}, []int{-2, -1, 3}}},
46+
ans15{[][]int{{-10, 2, 8}, {-10, 3, 7}, {-10, 4, 6}, {-10, 5, 5}, {-8, 2, 6}, {-8, 3, 5}, {-8, 4, 4}, {-7, -1, 8},
47+
{-7, 2, 5}, {-7, 3, 4}, {-6, -2, 8}, {-6, -1, 7}, {-6, 2, 4}, {-5, -3, 8}, {-5, -2, 7}, {-5, -1, 6}, {-5, 2, 3},
48+
{-4, -3, 7}, {-4, -2, 6}, {-4, -1, 5}, {-4, 2, 2}, {-3, -3, 6}, {-3, -2, 5}, {-3, -1, 4}, {-2, -1, 3}}},
4949
},
5050
}
5151

0 commit comments

Comments
 (0)