Skip to content

Commit 1c147dc

Browse files
authored
Create 820. Short Encoding of Words.py
1 parent 7beded5 commit 1c147dc

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution:
2+
def minimumLengthEncoding(self, words: List[str]) -> int:
3+
words = sorted(set(words), key=lambda word: word[::-1])
4+
5+
answer = 0
6+
7+
for i, word in enumerate(words):
8+
if i + 1 < len(words) and words[i + 1].endswith(word):
9+
continue
10+
11+
answer += len(word) + 1
12+
13+
return answer

0 commit comments

Comments
 (0)