Skip to content

Commit 39b6675

Browse files
committed
测试
1 parent 5b49b67 commit 39b6675

File tree

9 files changed

+201
-176
lines changed

9 files changed

+201
-176
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
package ba_shu_zi_fan_yi_cheng_zi_fu_chuan_lcof
2-
3-
var TranslateNum = translateNum
1+
package ba_shu_zi_fan_yi_cheng_zi_fu_chuan_lcof
2+
3+
var TranslateNum = translateNum
Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
package ba_shu_zi_fan_yi_cheng_zi_fu_chuan_lcof
2-
3-
import "strconv"
4-
5-
func translateNum(num int) int {
6-
var s = strconv.Itoa(num)
7-
var n = len(s)
8-
var dp = []int{1, 1}
9-
for i := 2; i < n+1; i++ {
10-
var o, e = strconv.Atoi(s[i-2 : i])
11-
if e != nil {
12-
panic(e)
13-
}
14-
dp = append(dp, dp[1]+Btoi(9 < o && o < 26)*dp[0])
15-
dp = dp[1:]
16-
}
17-
return dp[1]
18-
}
19-
func Btoi(b bool) int {
20-
if b {
21-
return 1
22-
}
23-
return 0
24-
}
1+
package ba_shu_zi_fan_yi_cheng_zi_fu_chuan_lcof
2+
3+
import "strconv"
4+
5+
func translateNum(num int) int {
6+
var s = strconv.Itoa(num)
7+
var n = len(s)
8+
var dp = []int{1, 1}
9+
for i := 2; i < n+1; i++ {
10+
var o, e = strconv.Atoi(s[i-2 : i])
11+
if e != nil {
12+
panic(e)
13+
}
14+
dp = append(dp, dp[1]+Btoi(9 < o && o < 26)*dp[0])
15+
dp = dp[1:]
16+
}
17+
return dp[1]
18+
}
19+
func Btoi(b bool) int {
20+
if b {
21+
return 1
22+
}
23+
return 0
24+
}

design-circular-deque/index.go

Lines changed: 69 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,69 @@
1-
package design_circular_deque
2-
3-
import "errors"
4-
5-
type MyCircularDeque struct {
6-
capacity int
7-
deque []int
8-
}
9-
10-
func Constructor(capacity int) MyCircularDeque {
11-
if capacity < 1 {
12-
panic(errors.New("k greater than or equal one"))
13-
}
14-
return MyCircularDeque{capacity: capacity}
15-
}
16-
17-
func (d *MyCircularDeque) InsertFront(value int) bool {
18-
if d.IsFull() {
19-
return false
20-
}
21-
d.deque = append([]int{value}, d.deque...)
22-
return true
23-
}
24-
25-
func (d *MyCircularDeque) InsertLast(value int) bool {
26-
if d.IsFull() {
27-
return false
28-
}
29-
d.deque = append(d.deque, value)
30-
return true
31-
}
32-
33-
func (d *MyCircularDeque) DeleteFront() bool {
34-
if d.IsEmpty() {
35-
return false
36-
}
37-
d.deque = d.deque[1:]
38-
return true
39-
}
40-
41-
func (d *MyCircularDeque) DeleteLast() bool {
42-
if d.IsEmpty() {
43-
return false
44-
}
45-
d.deque = d.deque[:len(d.deque)-1]
46-
return true
47-
}
48-
49-
func (d *MyCircularDeque) GetFront() int {
50-
if d.IsEmpty() {
51-
return -1
52-
}
53-
return d.deque[0]
54-
}
55-
56-
func (d *MyCircularDeque) GetRear() int {
57-
if d.IsEmpty() {
58-
return -1
59-
}
60-
return d.deque[len(d.deque)-1]
61-
}
62-
63-
func (d *MyCircularDeque) IsEmpty() bool {
64-
return len(d.deque) == 0
65-
}
66-
67-
func (d *MyCircularDeque) IsFull() bool {
68-
return len(d.deque) >= d.capacity
69-
}
1+
package design_circular_deque
2+
3+
import "errors"
4+
5+
type MyCircularDeque struct {
6+
capacity int
7+
deque []int
8+
}
9+
10+
func Constructor(capacity int) MyCircularDeque {
11+
if capacity < 1 {
12+
panic(errors.New("k greater than or equal one"))
13+
}
14+
return MyCircularDeque{capacity: capacity}
15+
}
16+
17+
func (d *MyCircularDeque) InsertFront(value int) bool {
18+
if d.IsFull() {
19+
return false
20+
}
21+
d.deque = append([]int{value}, d.deque...)
22+
return true
23+
}
24+
25+
func (d *MyCircularDeque) InsertLast(value int) bool {
26+
if d.IsFull() {
27+
return false
28+
}
29+
d.deque = append(d.deque, value)
30+
return true
31+
}
32+
33+
func (d *MyCircularDeque) DeleteFront() bool {
34+
if d.IsEmpty() {
35+
return false
36+
}
37+
d.deque = d.deque[1:]
38+
return true
39+
}
40+
41+
func (d *MyCircularDeque) DeleteLast() bool {
42+
if d.IsEmpty() {
43+
return false
44+
}
45+
d.deque = d.deque[:len(d.deque)-1]
46+
return true
47+
}
48+
49+
func (d *MyCircularDeque) GetFront() int {
50+
if d.IsEmpty() {
51+
return -1
52+
}
53+
return d.deque[0]
54+
}
55+
56+
func (d *MyCircularDeque) GetRear() int {
57+
if d.IsEmpty() {
58+
return -1
59+
}
60+
return d.deque[len(d.deque)-1]
61+
}
62+
63+
func (d *MyCircularDeque) IsEmpty() bool {
64+
return len(d.deque) == 0
65+
}
66+
67+
func (d *MyCircularDeque) IsFull() bool {
68+
return len(d.deque) >= d.capacity
69+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package design_circular_queue
2+
3+
import (
4+
"testing"
5+
6+
"gotest.tools/v3/assert"
7+
)
8+
9+
func TestMyCircularQueue(t *testing.T) {
10+
11+
var results = []any{}
12+
var circularQueue = Constructor(3) // 设置长度为 3
13+
results = append(results, (circularQueue.EnQueue(1))) // 返回 true
14+
results = append(results, (circularQueue.EnQueue(2))) // 返回 true
15+
results = append(results, (circularQueue.EnQueue(3))) // 返回 true
16+
results = append(results, (circularQueue.EnQueue(4))) // 返回 false,队列已满
17+
results = append(results, (circularQueue.Rear())) // 返回 3
18+
results = append(results, (circularQueue.IsFull())) // 返回 true
19+
results = append(results, (circularQueue.DeQueue())) // 返回 true
20+
results = append(results, (circularQueue.EnQueue(4))) // 返回 true
21+
results = append(results, (circularQueue.Rear())) // 返回 4
22+
assert.DeepEqual(t, results, []any{true, true, true, false, 3, true, true, true, 4})
23+
}

design-circular-queue/index.go

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,53 @@
1-
package design_circular_queue
2-
3-
import "errors"
4-
5-
type MyCircularQueue struct {
6-
capacity int
7-
queue []int
8-
}
9-
10-
func Constructor(capacity int) MyCircularQueue {
11-
if capacity < 1 {
12-
panic(errors.New("k greater than or equal one"))
13-
}
14-
return MyCircularQueue{capacity: capacity}
15-
}
16-
17-
func (d *MyCircularQueue) EnQueue(value int) bool {
18-
if d.IsFull() {
19-
return false
20-
}
21-
d.queue = append(d.queue, value)
22-
return true
23-
}
24-
25-
func (d *MyCircularQueue) DeQueue() bool {
26-
if d.IsEmpty() {
27-
return false
28-
}
29-
d.queue = d.queue[1:]
30-
return true
31-
}
32-
33-
func (d *MyCircularQueue) Front() int {
34-
if d.IsEmpty() {
35-
return -1
36-
}
37-
return d.queue[0]
38-
}
39-
40-
func (d *MyCircularQueue) Rear() int {
41-
if d.IsEmpty() {
42-
return -1
43-
}
44-
return d.queue[len(d.queue)-1]
45-
}
46-
47-
func (d *MyCircularQueue) IsEmpty() bool {
48-
return len(d.queue) == 0
49-
}
50-
51-
func (d *MyCircularQueue) IsFull() bool {
52-
return len(d.queue) >= d.capacity
53-
}
1+
package design_circular_queue
2+
3+
import "errors"
4+
5+
type MyCircularQueue struct {
6+
capacity int
7+
queue []int
8+
}
9+
10+
func Constructor(capacity int) MyCircularQueue {
11+
if capacity < 1 {
12+
panic(errors.New("k greater than or equal one"))
13+
}
14+
return MyCircularQueue{capacity: capacity}
15+
}
16+
17+
func (d *MyCircularQueue) EnQueue(value int) bool {
18+
if d.IsFull() {
19+
return false
20+
}
21+
d.queue = append(d.queue, value)
22+
return true
23+
}
24+
25+
func (d *MyCircularQueue) DeQueue() bool {
26+
if d.IsEmpty() {
27+
return false
28+
}
29+
d.queue = d.queue[1:]
30+
return true
31+
}
32+
33+
func (d *MyCircularQueue) Front() int {
34+
if d.IsEmpty() {
35+
return -1
36+
}
37+
return d.queue[0]
38+
}
39+
40+
func (d *MyCircularQueue) Rear() int {
41+
if d.IsEmpty() {
42+
return -1
43+
}
44+
return d.queue[len(d.queue)-1]
45+
}
46+
47+
func (d *MyCircularQueue) IsEmpty() bool {
48+
return len(d.queue) == 0
49+
}
50+
51+
func (d *MyCircularQueue) IsFull() bool {
52+
return len(d.queue) >= d.capacity
53+
}

fmt.cmd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
deno fmt --config deno.json
1+
deno fmt --config deno.json
2+
go fmt ./...

group-anagrams/export.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
package group_anagrams
2-
3-
func GroupAnagrams(strs []string) [][]string {
4-
return groupAnagrams(strs)
5-
}
1+
package group_anagrams
2+
3+
func GroupAnagrams(strs []string) [][]string {
4+
return groupAnagrams(strs)
5+
}

group-anagrams/index.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
package group_anagrams
2-
3-
import (
4-
"sort"
5-
"strings"
6-
)
7-
8-
func groupAnagrams(strs []string) [][]string {
9-
mp := map[string][]string{}
10-
for _, str := range strs {
11-
slice := strings.Split(str, "")
12-
sort.Strings(slice)
13-
cnt := strings.Join(slice, "")
14-
mp[cnt] = append(mp[cnt], str)
15-
}
16-
ans := make([][]string, 0, len(mp))
17-
for _, v := range mp {
18-
ans = append(ans, v)
19-
}
20-
return ans
21-
}
1+
package group_anagrams
2+
3+
import (
4+
"sort"
5+
"strings"
6+
)
7+
8+
func groupAnagrams(strs []string) [][]string {
9+
mp := map[string][]string{}
10+
for _, str := range strs {
11+
slice := strings.Split(str, "")
12+
sort.Strings(slice)
13+
cnt := strings.Join(slice, "")
14+
mp[cnt] = append(mp[cnt], str)
15+
}
16+
ans := make([][]string, 0, len(mp))
17+
for _, v := range mp {
18+
ans = append(ans, v)
19+
}
20+
return ans
21+
}

test.cmd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
go test -v ./...
12
deno test --config deno.json

0 commit comments

Comments
 (0)