From f8ab473d6a42176c8a25c8e7c3fb4e4e5ddd042b Mon Sep 17 00:00:00 2001 From: Qiming Xu <458173774@qq.com> Date: Sun, 7 Jan 2024 00:31:08 +0000 Subject: [PATCH] leetcode: finished #820 --- content/leetcode/2024/1.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/content/leetcode/2024/1.md b/content/leetcode/2024/1.md index 6f1b2a16..c9b4a037 100644 --- a/content/leetcode/2024/1.md +++ b/content/leetcode/2024/1.md @@ -3,6 +3,32 @@ title: 2024.1 draft: false --- +# 2024.1.7 + +```python +# +# @lc app=leetcode.cn id=820 lang=python3 +# +# [820] 单词的压缩编码 +# + +# @lc code=start +from typing import List + + +class Solution: + def minimumLengthEncoding(self, words: List[str]) -> int: + words = sorted(words, key=lambda x: len(x), reverse=True) + res = "" + for word in words: + if word + "#" not in res: + res += word + "#" + return len(res) + + +# @lc code=end +``` + # 2024.1.6 ```python