import java.util.*; public class Zipper { public String zipString(String str) { // write code here if(str.length() == 0 ) return str; int flag = 0; int num = 1; StringBuffer sb = new StringBuffer(); char tmp = str.charAt(0); for(int i = 1; i < str.length(); i++){ if(str.charAt(i) == tmp){ num++; flag = 1; } else{ sb.append(tmp); sb.append(num); tmp = str.charAt(i); num = 1; } } sb.append(tmp); sb.append(num); if(flag == 0 || sb.length() >= str.length()) return str; else return sb.toString(); } }