Longest String Chain LeetCode solution in Python
1# Runtime: 123 ms (Top 85.4%) | Memory: 16.81 MB (Top 58.4%)234class Solution:5def longestStrChain(self, words: List[str]) -> int:67words.sort(key=len)8dic = {}910for i in words:11dic[i] = 11213for j in range(len(i)):1415# creating words by deleting a letter16successor = i[:j] + i[j + 1 :]17if successor in dic:18dic[i] = max(dic[i], 1 + dic[successor])1920res = max(dic.values())21return res