classSolution{//记忆化HashMap<String,Integer> hashMap =newHashMap<>();publicintlongestStrChain(String[] words){for(String str: words){
hashMap.put(str,0);}int ans =0;for(String str : words){
ans =Math.max(ans,dfs(str));}return ans;}privateintdfs(String str){int res = hashMap.get(str);//大于0代表曾经计算过if(res >0){return res;}for(int i =0; i < str.length(); i++){String tmp = str.substring(0, i)+ str.substring(i+1);if(hashMap.containsKey(tmp)){
res =Math.max(res,dfs(tmp));}}
hashMap.put(str, res +1);return res +1;}}