Java compressing Strings

前端 未结 20 1042
误落风尘
误落风尘 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 09:59

    The following can be used if you are looking for a basic solution. Iterate through the string with one element and after finding all the element occurrences, remove that character. So that it will not interfere in the next search.

    public static void main(String[] args) {
        String string = "aaabbbbbaccc";
        int counter;
        String result="";
        int i=0;
        while (i
                                                            
提交回复
热议问题