Skip to content

Commit f305b24

Browse files
committed
提高第五题测试用例覆盖率
1 parent f6f44b0 commit f305b24

File tree

6 files changed

+108
-9
lines changed

6 files changed

+108
-9
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
profile.out
2+
node_modules/

6.ZigZagConversion/README.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## [5. Longest Palindromic Substring](https://leetcode.com/problems/longest-palindromic-substring/)
2+
3+
###### 2019/02/17
4+
5+
> #### 思路
6+
> abcbd
7+
> 二次循环
8+
> a
9+
> ab
10+
> abc
11+
> abcb
12+
> abcbd
13+
> b
14+
> bc
15+
> bcb -> 检测是否是是回文函数
16+
17+
18+
### TODO
19+
- [x] 测试用例通过
20+
- [ ] 双层for循环遍历一般都很慢,应该尽量避免写O(m*n)代码

6.ZigZagConversion/main.go

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package main
2+
3+
import "fmt"
4+
5+
// 有意思啊.传值还是传指针, very fun
6+
func coverStringIntoGraph(s string, r int) *[][]int {
7+
fmt.Println(s)
8+
graph:=&[][]int{}
9+
10+
return graph
11+
}
12+
13+
func convert(s string, numRows /*总列数*/ int) string {
14+
container := [][]string{}
15+
numCols := len(s) / numRows // 总行数
16+
numMid := numRows - 2
17+
graph := coverStringIntoGraph(s, numRows)
18+
fmt.Println(s, numCols, container, numMid,graph)
19+
return s
20+
}
21+
22+
func main() {
23+
fmt.Println(convert("PAYPALISHIRING", 4))
24+
}

6.ZigZagConversion/main_test.go

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package main
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
type para struct {
10+
str string
11+
row int
12+
}
13+
14+
type ans struct {
15+
str string
16+
}
17+
18+
type question struct {
19+
p para
20+
a ans
21+
}
22+
23+
func Test_OK(t *testing.T) {
24+
ast := assert.New(t)
25+
26+
qs := []question{
27+
question{
28+
p: para{
29+
str: "PAYPALISHIRING",
30+
row: 3,
31+
},
32+
a: ans{
33+
str: "PAHNAPLSIIGYIR",
34+
},
35+
},
36+
question{
37+
p: para{
38+
str: "PAYPALISHIRING",
39+
row: 4,
40+
},
41+
a: ans{
42+
str: "PINALSIGYAHRPI",
43+
},
44+
},
45+
}
46+
47+
for _, q := range qs {
48+
a, p := q.a, q.p
49+
ast.Equal(a.str, convert(p.str,p.row), "输入:%v", p)
50+
}
51+
52+
// ast.Panics(func() { longestPalindrome([]int{}, []int{}) }, "对空切片求中位数,却没有panic")
53+
54+
}

README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77

88

99

10-
### Go 语言是一个非常强大的语言 很棒!
10+
### Golang 是一个非常强大的语言 很棒!
1111

1212
Go 语言接受了函数式编程的一些想法,支持匿名函数与闭包。再如,Go 语言接受了以 ErLang 语言为代表的面向消息编程思想,支持 goroutine 和通道,并推荐使用消息而不是共享内存来进行并发编程。总体来说,Go 语言是一个非常现代化的语言,精小但非常强大。
1313

1414

1515

16-
### Go 语言最主要的特性
16+
### Golang 最主要的特性
1717
- 自动垃圾回收
1818
- 更丰富的内置类型
1919
- 函数多返回值
@@ -24,7 +24,7 @@ Go 语言接受了函数式编程的一些想法,支持匿名函数与闭包
2424
- 反射
2525
- 语言交互性
2626

27-
### Go适合用来做什么
27+
### Golang 适合用来做什么
2828
- **服务器编程** 以前如果使用C或者C++做的那些事情,用Go来做很合适,例如处理日志、数据打包、虚拟机处理、文件系统等。
2929

3030
- **分布式系统** 数据库代理器等
@@ -36,7 +36,7 @@ Go 语言接受了函数式编程的一些想法,支持匿名函数与闭包
3636
- **云平台** 目前国外很多云平台在采用Go开发,CloudFoundy的部分组建,前VMare的技术总监自己出来搞的apcera云平台。
3737

3838

39-
### Go 语言的基础
39+
### Golang 语言的基础
4040

4141
- 包声明
4242
- 引入包
@@ -45,7 +45,7 @@ Go 语言接受了函数式编程的一些想法,支持匿名函数与闭包
4545
- 语句 & 表达式
4646
- 注释
4747

48-
### Go 的 25 个关键字
48+
### Golang 的25个关键字
4949

5050
| break | default | func | interface | select |
5151
| :------: | :---------: | :----: | :-------: | :----: |
@@ -54,14 +54,14 @@ Go 语言接受了函数式编程的一些想法,支持匿名函数与闭包
5454
| const | fallthrough | if | range | type |
5555
| continue | for | import | return |
5656

57-
### Go 的基本类型
57+
### Golang 的基本类型
5858
| bool | 布尔值 | | | | |
5959
| :-------: | :---------: | :-------------------: | :----: | :----: | :-----: |
6060
| string | 字符串 |
6161
| int | int8 | int16 | int32 | int64 |
6262
| uint | uint8 | uint16 | uint32 | uint64 | uintptr |
6363
| float32 | float64 | 小数/浮点数 |
64-
| complex64 | complete128 | 这你妈是复数啊,擦! |
64+
| complex64 | complete128 | 复数 |
6565
| byte | uint8别名 |
6666
| rune | int32别名 | 表示一个 Unicode 码点 |
6767

@@ -81,7 +81,7 @@ Go 语言接受了函数式编程的一些想法,支持匿名函数与闭包
8181

8282

8383

84-
### bug free
84+
### Bug Free
8585
为什么我的代码总被同事吐槽bug多呢?
8686
浅层的考虑是,考虑的不够周全,
8787
深层的考虑是,写代码的习惯不好.

profile.out

-1
This file was deleted.

0 commit comments

Comments
 (0)