class Solution { boolean containsSub(String s,String p){ int i,j; for(i=0,j=0;i=p.length())return true; return false; } void removeStr(String p,LinkedList list){ if(list.contains(p)){ String s=""; for(int i=0;i map=new HashMap<>(); for(String s:strs) if(map.containsKey(s)) map.replace(s, map.get(s)+1); else map.put(s, 1); LinkedList list=new LinkedList<>(); for(String s:map.keySet()) list.addFirst(s); list.sort(new Comparator (){ @Override public int compare(String o1, String o2) { // TODO Auto-generated method stub return o2.length()-o1.length(); } }); int last=list.size(),i=0; while(i 1) removeStr(list.get(i),list); else i++; if(last==list.size())break; else last=list.size(); } if(list.size()==0)return -1; return list.getFirst().length(); }}
坑:判断包含关系和递归删除