Introduction
In this Python challenge, we will be compressing a string by replacing repeated characters with a count of the repetition. The compressed string will only be returned if it saves space.
In this Python challenge, we will be compressing a string by replacing repeated characters with a count of the repetition. The compressed string will only be returned if it saves space.
Given a string, compress it such that 'AAABCCDDDD' becomes 'A3BC2D4'. The compressed string should only be returned if it saves space. If the compressed string is longer than the original string, return the original string. The string is case sensitive and can be assumed to be ASCII. Additional data structures can be used and it can be assumed that the string fits in memory.
The following requirements must be met:
The following examples demonstrate the expected input and output of the function:
In this Python challenge, we have learned how to compress a string by replacing repeated characters with a count of the repetition. We have also learned that the compressed string should only be returned if it saves space and that the string is case sensitive, ASCII, and fits in memory.