We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 17e381e commit fbf4ce3Copy full SHA for fbf4ce3
820.单词的压缩编码.js
@@ -0,0 +1,29 @@
1
+/**
2
+ * @param {string[]} words
3
+ * @return {number}
4
+ */
5
+var minimumLengthEncoding = function(words) {
6
+ words.sort((a, b) => b.length - a.length);
7
+ const map = new Map();
8
+ for (const word of words) {
9
+ const list = map.get(word[word.length - 1]) || [];
10
+ let i = 0;
11
+ while (i < list.length) {
12
+ if (list[i].lastIndexOf(word) === list[i].length - word.length) {
13
+ break;
14
+ }
15
+ i++;
16
17
+ if (i === list.length) {
18
+ list.push(word);
19
+ map.set(word[word.length - 1], list);
20
21
22
+ let result = 0;
23
+ for (const list of map.values()) {
24
+ for (const word of list) {
25
+ result += word.length + 1;
26
27
28
+ return result;
29
+};
0 commit comments