Sobes.tech
Intern — Senior

String compression

livecode

Task condition

Given a string that may contain consecutive repeated characters, if a character repeats multiple times in a row, leave only one copy and indicate the number of repetitions. If a character appears only once, it remains unchanged. Example: AAABBBCCXYZDDDD → A3B3C2XYZD4

public String compress(String s) {
    // ...
}