Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit 82f02b4

Browse files
aQuaaQua
authored andcommitted
820 added
1 parent 0d6e410 commit 82f02b4

File tree

4 files changed

+73
-2
lines changed

4 files changed

+73
-2
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# [820. Short Encoding of Words](https://leetcode.com/problems/short-encoding-of-words/)
2+
3+
## 题目
4+
5+
Given a list of words, we may encode it by writing a reference string S and a list of indexes A.
6+
7+
For example, if the list of words is ["time", "me", "bell"], we can write it as S = "time#bell#"and indexes = [0, 2, 5].
8+
9+
Then for each index, we will recover the word by reading from the reference string from that index until we reach a "#" character.
10+
11+
What is the length of the shortest reference string S possible that encodes the given words?
12+
13+
Example:
14+
15+
```text
16+
Input: words = ["time", "me", "bell"]
17+
Output: 10
18+
Explanation: S = "time#bell#" and indexes = [0, 2, 5].
19+
```
20+
21+
Note:
22+
23+
1. 1 <= words.length<= 2000.
24+
1. 1 <=words[i].length<= 7.
25+
1. Each wordhas onlylowercase letters.
26+
27+
## 解题思路
28+
29+
见程序注释
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package problem0820
2+
3+
func minimumLengthEncoding(words []string) int {
4+
5+
return 0
6+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package problem0820
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
// tcs is testcase slice
11+
var tcs = []struct {
12+
words []string
13+
ans int
14+
}{
15+
16+
17+
18+
// 可以有多个 testcase
19+
}
20+
21+
func Test_minimumLengthEncoding(t *testing.T) {
22+
ast := assert.New(t)
23+
24+
for _, tc := range tcs {
25+
fmt.Printf("~~%v~~\n", tc)
26+
ast.Equal(tc.ans, minimumLengthEncoding(tc.words), "输入:%v", tc)
27+
}
28+
}
29+
30+
func Benchmark_minimumLengthEncoding(b *testing.B) {
31+
for i := 0; i < b.N; i++ {
32+
for _, tc := range tcs {
33+
minimumLengthEncoding(tc.words)
34+
}
35+
}
36+
}

leetcode.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"Username": "aQuaYi",
33
"Ranking": 1144,
4-
"Updated": "2018-05-16T09:48:26.298742405+08:00",
4+
"Updated": "2018-05-16T09:51:31.24856088+08:00",
55
"Record": {
66
"Easy": {
77
"Solved": 167,
@@ -9529,7 +9529,7 @@
95299529
"ID": 792,
95309530
"Title": "Number of Matching Subsequences",
95319531
"TitleSlug": "number-of-matching-subsequences",
9532-
"PassRate": "35%",
9532+
"PassRate": "36%",
95339533
"Difficulty": "Medium",
95349534
"IsAccepted": true,
95359535
"IsPaid": false,

0 commit comments

Comments
 (0)