Skip to content

Commit

Permalink
optimization code level from A to A+
Browse files Browse the repository at this point in the history
  • Loading branch information
halfrost committed Aug 26, 2020
1 parent 7b73077 commit 96c36de
Show file tree
Hide file tree
Showing 519 changed files with 2,341 additions and 2,322 deletions.
13 changes: 13 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"go.formatTool": "gofmt",
"go.formatFlags": [
"-s"
],
"[go]": {
"editor.insertSpaces": false,
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
}
}
}
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
<img src='./logo.png'>
</p>

<p align='center'>
<img alt="GitHub All Releases" src="https://img.shields.io/github/downloads/halfrost/LeetCode-Go/total?label=PDF%20downloads">
<img src="https://github.com/halfrost/LeetCode-Go/workflows/Deploy%20leetcode-cookbook/badge.svg?branch=master">
<img src="https://travis-ci.org/halfrost/LeetCode-Go.svg?branch=master">
<img src="https://goreportcard.com/badge/github.com/halfrost/LeetCode-Go">
</p>

<p align='center'>
<a href="https://leetcode.com/halfrost/"><img src="https://img.shields.io/badge/@halfrost-8751-yellow.svg">
<img src="https://img.shields.io/badge/language-Golang-abcdef.svg">
Expand All @@ -20,8 +27,6 @@
<a href=""><img src="https://img.shields.io/badge/license-CC-000000.svg"></a>
<img src="https://img.shields.io/badge/made%20with-=1-blue.svg">
<img src="https://visitor-badge.laobi.icu/badge?page_id=halfrost.LeetCode-Go">
<img src="https://github.com/halfrost/LeetCode-Go/workflows/Deploy%20leetcode-cookbook/badge.svg?branch=master">
<img src="https://travis-ci.org/halfrost/LeetCode-Go.svg?branch=master">
</p>

支持 Progressive Web Apps 和 Dark Mode 的题解电子书《LeetCode Cookbook》 <a href="https://books.halfrost.com/leetcode/" rel="nofollow">Online Reading</a>
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module LeetCode-Go

go 1.14
12 changes: 5 additions & 7 deletions leetcode/0001.Two-Sum/1. Two Sum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,30 @@ type ans1 struct {
func Test_Problem1(t *testing.T) {

qs := []question1{

question1{
{
para1{[]int{3, 2, 4}, 6},
ans1{[]int{1, 2}},
},

question1{
{
para1{[]int{3, 2, 4}, 5},
ans1{[]int{0, 1}},
},

question1{
{
para1{[]int{0, 8, 7, 3, 3, 4, 2}, 11},
ans1{[]int{1, 3}},
},

question1{
{
para1{[]int{0, 1}, 1},
ans1{[]int{0, 1}},
},

question1{
{
para1{[]int{0, 3}, 5},
ans1{[]int{}},
},

// 如需多个测试,可以复制上方元素。
}

Expand Down
16 changes: 8 additions & 8 deletions leetcode/0002.Add-Two-Numbers/2. Add Two Numbers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,42 +29,42 @@ func Test_Problem2(t *testing.T) {

qs := []question2{

question2{
{
para2{[]int{}, []int{}},
ans2{[]int{}},
},

question2{
{
para2{[]int{1}, []int{1}},
ans2{[]int{2}},
},

question2{
{
para2{[]int{1, 2, 3, 4}, []int{1, 2, 3, 4}},
ans2{[]int{2, 4, 6, 8}},
},

question2{
{
para2{[]int{1, 2, 3, 4, 5}, []int{1, 2, 3, 4, 5}},
ans2{[]int{2, 4, 6, 8, 0, 1}},
},

question2{
{
para2{[]int{1}, []int{9, 9, 9, 9, 9}},
ans2{[]int{0, 0, 0, 0, 0, 1}},
},

question2{
{
para2{[]int{9, 9, 9, 9, 9}, []int{1}},
ans2{[]int{0, 0, 0, 0, 0, 1}},
},

question2{
{
para2{[]int{2, 4, 3}, []int{5, 6, 4}},
ans2{[]int{7, 0, 8}},
},

question2{
{
para2{[]int{1, 8, 3}, []int{7, 1}},
ans2{[]int{8, 9, 3}},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@ func Test_Problem3(t *testing.T) {

qs := []question3{

question3{
{
para3{"abcabcbb"},
ans3{3},
},

question3{
{
para3{"bbbbb"},
ans3{1},
},

question3{
{
para3{"pwwkew"},
ans3{3},
},

question3{
{
para3{""},
ans3{0},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ func Test_Problem4(t *testing.T) {

qs := []question4{

question4{
{
para4{[]int{1, 3}, []int{2}},
ans4{2.0},
},

question4{
{
para4{[]int{1, 2}, []int{3, 4}},
ans4{2.5},
},
Expand Down
8 changes: 4 additions & 4 deletions leetcode/0007.Reverse-Integer/7. Reverse Integer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@ func Test_Problem7(t *testing.T) {

qs := []question7{

question7{
{
para7{321},
ans7{123},
},

question7{
{
para7{-123},
ans7{-321},
},

question7{
{
para7{120},
ans7{21},
},

question7{
{
para7{1534236469},
ans7{0},
},
Expand Down
14 changes: 7 additions & 7 deletions leetcode/0009.Palindrome-Number/9. Palindrome Number_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,37 @@ func Test_Problem9(t *testing.T) {

qs := []question9{

question9{
{
para9{121},
ans9{true},
},

question9{
{
para9{-121},
ans9{false},
},

question9{
{
para9{10},
ans9{false},
},

question9{
{
para9{321},
ans9{false},
},

question9{
{
para9{-123},
ans9{false},
},

question9{
{
para9{120},
ans9{false},
},

question9{
{
para9{1534236469},
ans9{false},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ func Test_Problem11(t *testing.T) {

qs := []question11{

question11{
{
para11{[]int{1, 8, 6, 2, 5, 4, 8, 3, 7}},
ans11{49},
},

question11{
{
para11{[]int{1, 1}},
ans11{1},
},
Expand Down
12 changes: 6 additions & 6 deletions leetcode/0013.Roman-to-Integer/13. Roman to Integer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,32 @@ func Test_Problem13(t *testing.T) {

qs := []question13{

question13{
{
para13{"III"},
ans13{3},
},

question13{
{
para13{"IV"},
ans13{4},
},

question13{
{
para13{"IX"},
ans13{9},
},

question13{
{
para13{"LVIII"},
ans13{58},
},

question13{
{
para13{"MCMXCIV"},
ans13{1994},
},

question13{
{
para13{"MCMXICIVI"},
ans13{2014},
},
Expand Down
20 changes: 10 additions & 10 deletions leetcode/0015.3Sum/15. 3Sum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,26 @@ func Test_Problem15(t *testing.T) {

qs := []question15{

question15{
{
para15{[]int{0, 0, 0}},
ans15{[][]int{[]int{0, 0, 0}}},
ans15{[][]int{{0, 0, 0}}},
},

question15{
{
para15{[]int{-1, 0, 1, 2, -1, -4}},
ans15{[][]int{[]int{-1, 0, 1}, []int{-1, -1, 2}}},
ans15{[][]int{{-1, 0, 1}, {-1, -1, 2}}},
},

question15{
{
para15{[]int{-4, -2, -2, -2, 0, 1, 2, 2, 2, 3, 3, 4, 4, 6, 6}},
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}}},
ans15{[][]int{{-4, -2, 6}, {-4, 0, 4}, {-4, 1, 3}, {-4, 2, 2}, {-2, -2, 4}, {-2, 0, 2}}},
},

question15{
{
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}},
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},
[]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},
[]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}}},
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},
{-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},
{-4, -3, 7}, {-4, -2, 6}, {-4, -1, 5}, {-4, 2, 2}, {-3, -3, 6}, {-3, -2, 5}, {-3, -1, 4}, {-2, -1, 3}}},
},
}

Expand Down
10 changes: 5 additions & 5 deletions leetcode/0016.3Sum-Closest/16. 3Sum Closest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,27 @@ func Test_Problem16(t *testing.T) {

qs := []question16{

question16{
{
para16{[]int{-1, 0, 1, 1, 55}, 3},
ans16{2},
},

question16{
{
para16{[]int{0, 0, 0}, 1},
ans16{0},
},

question16{
{
para16{[]int{-1, 2, 1, -4}, 1},
ans16{2},
},

question16{
{
para16{[]int{1, 1, -1}, 0},
ans16{1},
},

question16{
{
para16{[]int{-1, 2, 1, -4}, 1},
ans16{2},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func Test_Problem17(t *testing.T) {

qs := []question17{

question17{
{
para17{"23"},
ans17{[]string{"ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"}},
},
Expand Down
Loading

0 comments on commit 96c36de

Please sign in to comment.