97. compress a string

JavaScript
Is this helpful ?

medium  - accepted / - tried

Given a string, compress the repeating letters with count number

compress('a') // 'a'
compress('aa') // 'a2'
compress('aaa') // 'a3'
compress('aaab') // 'a3b'
compress('aaabb') // 'a3b2'
compress('aaabba') // 'a3b2a'

Let's try to solve this problem within 10 mintues.

Discuss(39)