97. compress a string

easy  - 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'

What is time & space complexity of your approach?

(1)
(106)