Skip to content

Commit 96c36de

Browse files
committed
optimization code level from A to A+
1 parent 7b73077 commit 96c36de

File tree

519 files changed

+2341
-2322
lines changed

Some content is hidden

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

519 files changed

+2341
-2322
lines changed

.vscode/settings.json

Lines changed: 13 additions & 0 deletions
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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
<img src='./logo.png'>
88
</p>
99

10+
<p align='center'>
11+
<img alt="GitHub All Releases" src="https://img.shields.io/github/downloads/halfrost/LeetCode-Go/total?label=PDF%20downloads">
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+
</p>
16+
1017
<p align='center'>
1118
<a href="https://leetcode.com/halfrost/"><img src="https://img.shields.io/badge/@halfrost-8751-yellow.svg">
1219
<img src="https://img.shields.io/badge/language-Golang-abcdef.svg">
@@ -20,8 +27,6 @@
2027
<a href=""><img src="https://img.shields.io/badge/license-CC-000000.svg"></a>
2128
<img src="https://img.shields.io/badge/made%20with-=1-blue.svg">
2229
<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">
2530
</p>
2631

2732
支持 Progressive Web Apps 和 Dark Mode 的题解电子书《LeetCode Cookbook》 <a href="https://books.halfrost.com/leetcode/" rel="nofollow">Online Reading</a>

go.mod

Lines changed: 3 additions & 0 deletions
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

Lines changed: 5 additions & 7 deletions
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

Lines changed: 8 additions & 8 deletions
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 7 additions & 7 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 6 additions & 6 deletions
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

Lines changed: 10 additions & 10 deletions
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

leetcode/0016.3Sum-Closest/16. 3Sum Closest_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,27 @@ func Test_Problem16(t *testing.T) {
2727

2828
qs := []question16{
2929

30-
question16{
30+
{
3131
para16{[]int{-1, 0, 1, 1, 55}, 3},
3232
ans16{2},
3333
},
3434

35-
question16{
35+
{
3636
para16{[]int{0, 0, 0}, 1},
3737
ans16{0},
3838
},
3939

40-
question16{
40+
{
4141
para16{[]int{-1, 2, 1, -4}, 1},
4242
ans16{2},
4343
},
4444

45-
question16{
45+
{
4646
para16{[]int{1, 1, -1}, 0},
4747
ans16{1},
4848
},
4949

50-
question16{
50+
{
5151
para16{[]int{-1, 2, 1, -4}, 1},
5252
ans16{2},
5353
},

leetcode/0017.Letter-Combinations-of-a-Phone-Number/17. Letter Combinations of a Phone Number_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func Test_Problem17(t *testing.T) {
2626

2727
qs := []question17{
2828

29-
question17{
29+
{
3030
para17{"23"},
3131
ans17{[]string{"ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"}},
3232
},

0 commit comments

Comments
 (0)