Day 17 Task:
5. String Compression: https://leetcode.com/problems/string-compression/
Solutions:
class Solution:
def compress(self, chars: List[str]) -> int:
curr = ""
l_index = 0
c = 0
i = 0
while(i < len(chars)):
if(chars[i] != curr):
curr = chars[i]
l_index = i
i += 1
elif((chars[i] == curr) and (i == l_index + 1)):
chars[i] = "2"
i += 1
elif(chars[i] == curr):
chars[l_index+1] = str(int(chars[l_index+1])+1)
del chars[i]
i = 0
while(i < len(chars)):
if(len(chars[i]) > 1):
for j in range(len(chars[i])-1, -1, -1):
chars.insert(i+1, chars[i][j])
del chars[i]
i += 1
return len(chars)