1/11
Loading...
📦String Compression!
Let's compress "aabcccde"! Consecutive same chars to char+count!
Loading...
Let's compress "aabcccde"! Consecutive same chars to char+count!
When chatting with friends, repeating the same character wastes data! Compress consecutive identical characters into 'character+count' format. However, if the compressed length is not shorter, return the original.
"aabcccde"
"a2b1c3d1e1"
a:2, b:1, c:3, d:1, e:1 Compressed: a2b1c3d1e1 (length 10 vs original 8) Original is shorter, return "aabcccde"!
"aaaaaaaaaa"
"a10"
10 consecutive a's! Compressed: a10 (length 3 vs original 10) Compressed is shorter, return "a10"!