package LongestRun;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
public class LongestRun {
public static String longestRun(String str){
Map map = new HashMap();
for (int i = 0; i
char a = str.charAt(i);
int j = i + 1;
while(j
char b = str.charAt(j);
if (a != b) {
break;
}
j++;
}
Integer n = map.get(String.valueOf(a));
if (n == null || n
map.put(String.valueOf(a), j-i);
}
i = j- 1;
}
String cString = "";
int n1 =0;
StringBuffer stringBuffer = new StringBuffer();
for(Entry entry: map.entrySet()){
if(entry.getValue() > n1){
n1 = entry.getValue();
cString = entry.getKey();
}
}
stringBuffer.append(cString+" "+n1+" ");
for(Entry entry: map.entrySet()){
if(entry.getValue() == n1){
n1 = entry.getValue();
cString = entry.getKey();
}
}
stringBuffer.append(cString+" "+n1+" ");
return stringBuffer.toString();
}
}