Super Simple Python


  • -1
    C
        if len(chars) <= 1:
            return len(chars)
        result = ""
        i = 0
        while i < len(chars):
            print(i, chars[i])
            k = i
            count = 1
            while k < len(chars) - 1:
                if chars[k] == chars[k+1]:
                    count += 1
                    k += 1
                else:
                    break
            if count == 1:
                result += chars[i]
                i += 1
            else:
                result += chars[i] + str(count)
                i += count
        
        #print(result)
        for i,v in enumerate(result):
            chars[i] = v
        
        return len(result)

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.