-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompressStringOPTIMIZEd.py
More file actions
30 lines (22 loc) · 943 Bytes
/
compressStringOPTIMIZEd.py
File metadata and controls
30 lines (22 loc) · 943 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
def compressString(self, chars):
ansNewArr = 0
i = 0
while i < len(chars):
ctConseChars = 0
letter = chars[i]
while i < len(chars) and chars[i] == letter:
ctConseChars += 1
i += 1
#letter a is assigned to ansNewArr
chars[ansNewArr] = letter
ansNewArr += 1
if ctConseChars > 1:
# chars[ansNewArr] = ctConseChars
# else:
# print("1")
for c in str(ctConseChars):
chars[ansNewArr] = c
ansNewArr += 1
#ctConseChars = 0
#a = str(5)
return ansNewArr