Beispiel für eine Python-Codelösung --1.6 Komprimierung von Zeichenketten
def compressBad(input_str):
compressedString = ""
countConsecutive = 0
for i in range(len(input_str)):
countConsecutive = countConsecutive + 1
if i+1 >= len(input_str) or input_str[i] != input_str[i+1]:
compressedString = compressedString + input_str[i] + str(countConsecutive)
countConsecutive = 0
return compressedString if len(compressedString) < len(input_str) else input_str
input_str = "aabcccccaaa"
print(compressBad(input_str))