2
def minimumLengthEncoding(self, words):7
# helper function to judge leaf node8
isLeafNode = lambda node: len(node) == 010
# collection of tail nodes14
unique_words = set(words)17
for word in unique_words:19
# build suffix trie from root node22
# scan each character in reversed order23
for char in reversed(word):26
cur[char] = cur.get(char, dict())31
# save tail nodes with corresponding word length, +1 is for '#' symbol32
tail_nodes.append((cur, len(word) + 1))34
# summation of the length with all tail node which is also a leaf node36
suffix_length for node, suffix_length in tail_nodes if isLeafNode(node)