Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 34eeadd

Browse files
committedAug 31, 2019
feat: 1079
1 parent 013835c commit 34eeadd

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed
 
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# [1079. Letter Tile Possibilities](https://leetcode.com/problems/letter-tile-possibilities/)
2+
3+
## 2019/08/31
4+
5+
### 题目 💗[medium]
6+
7+
You have a set of tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make.
8+
9+
Example 1:
10+
11+
```bash
12+
Input: "AAB"
13+
Output: 8
14+
Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA".
15+
```
16+
17+
Example 2:
18+
19+
```bash
20+
Input: "AAABBC"
21+
Output: 188
22+
```
23+
24+
Note:
25+
26+
- 1 <= tiles.length <= 7
27+
- tiles consists of uppercase English letters.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package numTilePossibilities
2+
3+
func numTilePossibilities(tiles string) int {
4+
res := []string{""}
5+
6+
for _, tile := range tiles {
7+
for _, ee := range res {
8+
for i := 0; i <= len(ee); i++ {
9+
temp := ee[:i] + string(tile) + ee[i:]
10+
res = append(res, temp)
11+
}
12+
}
13+
}
14+
Map := make(map[string]bool, len(res))
15+
for _, e := range res {
16+
Map[string(e)] = true
17+
}
18+
return len(Map) - 1
19+
}
20+
21+
// func subsets(nums []int) [][]int {
22+
// res := [][]int{[]int{}}
23+
// for _, e := range nums {
24+
// for _, ee := range res {
25+
// res = append(res, append([]int{e}, ee...))
26+
// }
27+
// }
28+
// return res
29+
// }
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package numTilePossibilities
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
var tcs = []struct {
10+
N1 string
11+
ans int
12+
}{
13+
{
14+
"AAB",
15+
8,
16+
},
17+
}
18+
19+
func Test_bitwiseComplement(t *testing.T) {
20+
ast := assert.New(t)
21+
for _, tc := range tcs {
22+
ast.Equal(tc.ans, numTilePossibilities(tc.N1), "输入:%v", tc)
23+
}
24+
}

0 commit comments

Comments
 (0)
Failed to load comments.