Skip to content

Latest commit

 

History

History
27 lines (18 loc) · 427 Bytes

820.md

File metadata and controls

27 lines (18 loc) · 427 Bytes

Short Encoding of Words

Description

link


Solution

  • See Code

Code

O(n K^2)

class Solution:
    def minimumLengthEncoding(self, words: List[str]) -> int:
        s = set(words)
        for w in words:
            for i in range(1, len(w)):
                s.discard(w[i:])
        return len(s) + sum([len(w) for w in s])