public Set<String> findRepeatedSubString(String s,int length){
if(s==null||s.length()==0) return null;
Set<String> checkSet = new HashSet<String>();
Set<String> result = new TreeSet<String>();
for(int i=0;i<s.length()-length+1;i++){
if(!checkSet.contains(s.substring(i,i+length)))
checkSet.add(s.substring(i,i+length));
else
result.add(s.substring(i,i+length));
}
if(result.size()==0) return null;
return result;
No comments:
Post a Comment