Skip to content

Commit ea2ccfe

Browse files
committed
Add solution and test-cases for problem 1079
1 parent d9d2a4a commit ea2ccfe

File tree

3 files changed

+43
-22
lines changed

3 files changed

+43
-22
lines changed

leetcode/1001-1100/1079.Letter-Tile-Possibilities/README.md

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
11
# [1079.Letter Tile Possibilities][title]
22

3-
> [!WARNING|style:flat]
4-
> This question is temporarily unanswered if you have good ideas. Welcome to [Create Pull Request PR](https://github.com/kylesliu/awesome-golang-algorithm)
5-
63
## Description
4+
You have `n` `tiles`, where each tile has one letter `tiles[i]` printed on it.
5+
6+
Return the number of possible non-empty sequences of letters you can make using the letters printed on those `tiles`.
77

88
**Example 1:**
99

1010
```
11-
Input: a = "11", b = "1"
12-
Output: "100"
11+
Input: tiles = "AAB"
12+
Output: 8
13+
Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA".
1314
```
1415

15-
## 题意
16-
> ...
16+
**Example 2:**
1717

18-
## 题解
19-
20-
### 思路1
21-
> ...
22-
Letter Tile Possibilities
23-
```go
18+
```
19+
Input: tiles = "AAABBC"
20+
Output: 188
2421
```
2522

23+
**Example 3:**
24+
25+
```
26+
Input: tiles = "V"
27+
Output: 1
28+
```
2629

2730
## 结语
2831

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
package Solution
22

3-
func Solution(x bool) bool {
4-
return x
3+
func Solution(tiles string) int {
4+
count := [26]int{}
5+
for _, c := range tiles {
6+
count[c-'A']++
7+
}
8+
var dfs func() int
9+
dfs = func() int {
10+
r := 1
11+
for i := 0; i < 26; i++ {
12+
if count[i] == 0 {
13+
continue
14+
}
15+
count[i]--
16+
r += dfs()
17+
count[i]++
18+
}
19+
return r
20+
21+
}
22+
return dfs() - 1
523
}

leetcode/1001-1100/1079.Letter-Tile-Possibilities/Solution_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ func TestSolution(t *testing.T) {
1010
// 测试用例
1111
cases := []struct {
1212
name string
13-
inputs bool
14-
expect bool
13+
inputs string
14+
expect int
1515
}{
16-
{"TestCase", true, true},
17-
{"TestCase", true, true},
18-
{"TestCase", false, false},
16+
{"TestCase1", "AAB", 8},
17+
{"TestCase2", "AAABBC", 188},
18+
{"TestCase3", "V", 1},
1919
}
2020

2121
// 开始测试
@@ -30,10 +30,10 @@ func TestSolution(t *testing.T) {
3030
}
3131
}
3232

33-
// 压力测试
33+
// 压力测试
3434
func BenchmarkSolution(b *testing.B) {
3535
}
3636

37-
// 使用案列
37+
// 使用案列
3838
func ExampleSolution() {
3939
}

0 commit comments

Comments
 (0)