| 1 | public class Compress { |
| 2 | |
| 3 | public static String compressq(String str){ |
| 4 | String newstr = ""; |
| 5 | for(int i=0 ; i<str.length() ; i++){ |
| 6 | Integer count =1; |
| 7 | while( i < str.length()-1 && str.charAt(1) == str.charAt(i+1) ){ |
| 8 | count++; |
| 9 | i++; |
| 10 | } |
| 11 | newstr += str.charAt(i); |
| 12 | if(count > 1){ |
| 13 | newstr += count.toString(); |
| 14 | } |
| 15 | } |
| 16 | return newstr; |
| 17 | } |
| 18 | |
| 19 | |
| 20 | |
| 21 | public static void main(String[] args) { |
| 22 | String str = "aavv"; |
| 23 | System.out.print(compressq(str)); |
| 24 | |
| 25 | } |
| 26 | } |
| 27 | //time Complexcity O(N) :) #NIshit |
nothing calls this directly
no outgoing calls
no test coverage detected