Day 17 LeetCode
👨‍💻

Day 17 LeetCode

Tags
Data Structures
Python
Java
Computer Science
Published
Jan 24, 2021

Day 17 Task:

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)