Skip to content

Commit 55c2bc9

Browse files
aQuaaQua
aQua
authored and
aQua
committed
91 added
1 parent b0acab4 commit 55c2bc9

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

Algorithms/0091.decode-ways/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# [91. Decode Ways](https://leetcode.com/problems/decode-ways/)
2+
3+
## 题目
4+
A message containing letters from `A-Z` is being encoded to numbers using the following mapping:
5+
6+
```
7+
'A' -> 1
8+
'B' -> 2
9+
...
10+
'Z' -> 26
11+
```
12+
13+
Given an encoded message containing digits, determine the total number of ways to decode it.
14+
15+
```
16+
For example,
17+
Given encoded message "12",
18+
it could be decoded as "AB" (1 2) or "L" (12).
19+
The number of ways decoding "12" is 2.
20+
```
21+
22+
## 解题思路
23+
24+
见程序注释
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package Problem0091
2+
3+
func numDecodings(s string) int {
4+
5+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package Problem0091
2+
3+
import (
4+
"testing"
5+
"fmt"
6+
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
type question struct {
11+
para
12+
ans
13+
}
14+
15+
// para 是参数
16+
type para struct {
17+
s string
18+
}
19+
20+
// ans 是答案
21+
type ans struct {
22+
one int
23+
}
24+
25+
func Test_Problem0091(t *testing.T) {
26+
ast := assert.New(t)
27+
28+
qs := []question{
29+
30+
question{
31+
para{
32+
,
33+
},
34+
ans{
35+
,
36+
},
37+
},
38+
39+
// 如需多个测试,可以复制上方元素。
40+
}
41+
42+
for _, q := range qs {
43+
a, p := q.ans, q.para
44+
fmt.Printf("~~%v~~\n", p)
45+
46+
ast.Equal(a.one, numDecodings(p. ), "输入:%v", p)
47+
}
48+
}

0 commit comments

Comments
 (0)