Skip to content

Commit 59bd94c

Browse files
authored
Merge pull request #463 from TTWShell/use-go-mod
use go mod and fix bug when upgrade go version
2 parents 5fc0b58 + 64de966 commit 59bd94c

File tree

9 files changed

+37
-13
lines changed

9 files changed

+37
-13
lines changed

.circleci/config.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
version: 2
22
jobs:
3-
build-go1.12:
3+
build-go1.16:
44
docker:
5-
- image: circleci/golang:1.12
5+
- image: circleci/golang:1.16
66
working_directory: /go/src/github.com/TTWShell/algorithms
77
steps:
88
- checkout
9-
- run: go get -t -v ./...
9+
- run: go mod vendor
1010
- run:
1111
name: Run unit tests
1212
command: |
@@ -18,4 +18,4 @@ workflows:
1818
version: 2
1919
build:
2020
jobs:
21-
- build-go1.12
21+
- build-go1.16

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
result
22
leetcode.db
33
.vscode/
4+
5+
vendor/*

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ language: go
22
go:
33
- 1.8
44
- 1.9
5+
- 1.16
56

67
before_install:
78
- go get -t -v ./...

data-structure/hash-table/hashtable_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ package hashtable
22

33
import (
44
"fmt"
5-
"github.com/stretchr/testify/assert"
65
"reflect"
76
"testing"
7+
8+
"github.com/stretchr/testify/assert"
89
)
910

1011
func TestNewHT(t *testing.T) {
@@ -61,8 +62,8 @@ func TestPut(t *testing.T) {
6162
assert.Equal(ht.size, MinSize*2)
6263

6364
for i := 0; i < 11; i++ {
64-
ht.Put(string(i), i*10)
65-
value, _ := ht.Get(string(i))
65+
ht.Put(string(rune(i)), i*10)
66+
value, _ := ht.Get(string(rune(i)))
6667
assert.Equal(value, i*10)
6768
}
6869
assert.Equal(ht.size, MinSize*4)

go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module github.com/TTWShell/algorithms
2+
3+
go 1.16
4+
5+
require github.com/stretchr/testify v1.7.0

go.sum

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
2+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
5+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
6+
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
7+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
8+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
9+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
10+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
11+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

leetcode/hash-table/commonChars.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func commonChars(A []string) []string {
4545
res := []string{}
4646
for k, count := range cache {
4747
for i := 0; i < count; i++ {
48-
res = append(res, string(k+97))
48+
res = append(res, string(rune(k+97)))
4949
}
5050
}
5151
return res

leetcode/math/convertToTitle.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ package lmath
1717
func convertToTitle(n int) string {
1818
r := ""
1919
for n > 0 {
20-
r = string((n-1)%26+'A') + r
20+
r = string(rune((n-1)%26+'A')) + r
2121
n = (n - 1) / 26
2222
}
2323
return r

leetcode/string/addBinary.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ Return "100".
88
*/
99
package lstring
1010

11+
import (
12+
"strconv"
13+
)
14+
1115
func addBinary(a string, b string) string {
1216
m, n := len(a), len(b)
1317
if m < n {
@@ -20,12 +24,12 @@ func addBinary(a string, b string) string {
2024

2125
plus, r := 0, ""
2226
for i := m - 1; i != -1; i-- {
23-
ans := int(a[i]) + int(b[i]) + plus
24-
if ans >= 98 {
25-
r = string(ans-'2') + r
27+
ans := int(a[i]) + int(b[i]) + plus - 48*2
28+
if ans >= 2 {
29+
r = strconv.Itoa(ans-2) + r
2630
plus = 1
2731
} else {
28-
r = string(ans-'0') + r
32+
r = strconv.Itoa(ans-0) + r
2933
plus = 0
3034
}
3135
}

0 commit comments

Comments
 (0)