Java compressing Strings

前端 未结 20 1065
误落风尘
误落风尘 2020-11-29 09:24

I need to create a method that receives a String and also returns a String.

Ex input: AAABBBBCC

Ex output: 3A4B2C

Well, this is quite embarrassing a

20条回答
  •  时光说笑
    2020-11-29 10:09

    consider the below Solution in which the String s1 identifies the unique characters that are available in a given String s (for loop 1), in the second for loop build a string s2 that contains unique character and no of times it is repeated by comparing string s1 with s.

    public static void main(String[] args) 
    {
        // TODO Auto-generated method stub
    
        String s = "aaaabbccccffffdeee";//given string
        String s1 = ""; // string to identify how many unique letters are available in a string
        String s2=""; //decompressed string will be appended to this string
        int count=0;
        for(int i=0;i

提交回复
热议问题