Skip to content

Latest commit

 

History

History

01-06 String Compression

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

String Compression

Problem

Given a string in the form 'AAAABBBBCCCCCDDEEEE' compress it to become 'A4B4C5D2E4'. For this problem, you can falsely "compress" strings of single or double letters. For instance, it is okay for 'AAB' to return 'A2B1' even though this technically takes more space.

The function should also be case sensitive, so that a string 'AAAaaa' returns 'A3a3'.

Code

Create your solution in the form:

def compress(s: str) -> str:
    pass

Example

>>> compress('AAAAABBBBCCCC')
'A5B4C4'