2
int dfs(unordered_map<string, int> &m, unordered_set<string> &setWords, const string &w) {3
if (m.count(w)) return m[w];6
for (int i = 0; i < w.size(); ++i) {7
auto preWord = w.substr(0, i) + w.substr(i + 1);8
if (setWords.count(preWord)) {9
int newLen = 1 + dfs(m, setWords, preWord);10
maxLen = max(newLen, maxLen);18
int longestStrChain(vector<string> &words) {19
unordered_map<string, int> m;20
unordered_set<string> setWords(words.begin(), words.end());23
for (auto &w : words) {24
res = max(res, dfs(m, setWords, w));