Skip to content

Commit 931cf16

Browse files
committed
feat:
1 parent 4321b6b commit 931cf16

File tree

4 files changed

+124
-2
lines changed

4 files changed

+124
-2
lines changed

algorithm/160.IntersectionofTwoLinkedLists/main_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@ import (
88
"github.com/stretchr/testify/assert"
99
)
1010

11+
var a *Helper.ListNode = Helper.Ints2LinkList([]int{4, 1, 8, 4, 5})
1112
var tcs = []struct {
1213
N1 *Helper.ListNode
1314
N2 *Helper.ListNode
14-
ans int
15+
ans *Helper.ListNode
1516
}{
1617
{
1718
Helper.Ints2LinkList([]int{4, 1, 8, 4, 5}),
1819
Helper.Ints2LinkList([]int{5, 0, 1, 8, 4, 5}),
19-
8,
20+
nil,
2021
},
2122
}
2223

algorithm/38.CountandSay/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# [38. Count and Say](https://leetcode.com/problems/count-and-say/)
2+
3+
## 2019/09/14
4+
5+
### 题目 💗[medium]
6+
7+
The count-and-say sequence is the sequence of integers with the first five terms as following:
8+
9+
```bash
10+
1. 1
11+
2. 11
12+
3. 21
13+
4. 1211
14+
5. 111221
15+
```
16+
17+
`1` is read off as "one 1" or 11.
18+
`11` is read off as "two 1s" or 21.
19+
`21` is read off as "one 2, then one 1" or 1211.
20+
Given an integer n where 1 ≤ n ≤ 30, generate the nth term of the count-and-say sequence.
21+
22+
Note: Each term of the sequence of integers will be represented as a string.
23+
24+
Example 1:
25+
26+
```bash
27+
Input: 1
28+
Output: "1"
29+
```
30+
31+
Example 2:
32+
33+
```bash
34+
Input: 4
35+
Output: "1211"
36+
```

algorithm/38.CountandSay/main.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package countAndSay
2+
3+
import (
4+
"fmt"
5+
"strconv"
6+
)
7+
8+
func countAndSay(n int) string {
9+
res := "1"
10+
for n > 1 {
11+
fmt.Println("=============times ============", n, res)
12+
n--
13+
temp := ""
14+
for len(res) > 0 {
15+
times := 0
16+
for len(res) > 0 && res[0] == '1' {
17+
times++
18+
res = res[1:]
19+
}
20+
if times == 1 {
21+
if len(res) == 0 {
22+
temp += "11"
23+
continue
24+
} else {
25+
temp += "1"
26+
}
27+
} else if times == 0 {
28+
temp += "1"
29+
temp += res[0:1]
30+
} else if times > 1 {
31+
temp += strconv.Itoa(times)
32+
temp += "1"
33+
}
34+
if len(res) > 0 {
35+
res = res[1:]
36+
}
37+
}
38+
res = temp
39+
}
40+
return res
41+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package countAndSay
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
var tcs = []struct {
10+
N1 int
11+
ans string
12+
}{
13+
// {
14+
// 1,
15+
// "1",
16+
// },
17+
// {
18+
// 2,
19+
// "11",
20+
// },
21+
// {
22+
// 3,
23+
// "21",
24+
// },
25+
// {
26+
// 4,
27+
// "1211",
28+
// },
29+
// {
30+
// 5,
31+
// "111221",
32+
// },
33+
// {
34+
// 6,
35+
// "312211",
36+
// },
37+
}
38+
39+
func Test_bitwiseComplement(t *testing.T) {
40+
ast := assert.New(t)
41+
for _, tc := range tcs {
42+
ast.Equal(tc.ans, countAndSay(tc.N1), "输入:%v", tc)
43+
}
44+
}

0 commit comments

Comments
 (0)