Skip to content
This repository was archived by the owner on Sep 22, 2021. It is now read-only.

Commit 94c3afd

Browse files
authored
Merge pull request #547 from frank731/master
Create 0443_String_Compression.py
2 parents d76b088 + 54a69ff commit 94c3afd

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution:
2+
def compress(self, chars: List[str]) -> int:
3+
read = 0
4+
while read < len(chars) - 1:
5+
count = 1
6+
read_next = read + 1
7+
while read < len(chars) - 1 and chars[read_next] == chars[read]:
8+
del chars[read_next]
9+
count += 1
10+
if count > 1:
11+
for char in str(count):
12+
chars.insert(read_next, char)
13+
read_next += 1
14+
read = read_next
15+
return len(chars)
16+

0 commit comments

Comments
 (0)