MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / Compress

Class Compress

Java/String/Compress.java:1–26  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1public 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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected