记录自己写的解答的构想。 无论如何,绝对不要当真。 很大的概率就是反例。
/* * * @ title : searchkeywordintext * @ description :查询关键字索引* @ param : @ param text * @ param : @ param kekey string * @ throws */publicmapstring,stringsearchkeywordintext (string text,liststringkeywords (throwskeynotfoundexcepceptiords ) String result=new HashMapString, 对于string Keywords.Foreach(key-(/过滤包含目标文本的if (key.index of ) text )0) keywords,按text拆分string [ ] sparard for(intI=0; i spArr.length; I )索引buffer.append (sparr [ I ].length ); if(I1sparr.length((/)2_5_7) indexbuffer.append ) _ ); (}//如果keywords发生冲突…这里是result.put(key,indexbuffer.toString ) ); }; ); if(result.isempty () ) { throw new KeyNotFoundException ('目标文件不匹配!' ); }返回结果; }如果大人物知道的话,请指出来。 谢谢你。