-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring_compression.py
More file actions
75 lines (59 loc) · 3.09 KB
/
Copy pathstring_compression.py
File metadata and controls
75 lines (59 loc) · 3.09 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# -*- coding: utf-8 -*-
"""
Created on Thu Jan 31 17:17:02 2019
@author: shrey
"""
#leetcode 443
def string_compression(string):
i=0
j=i+1
while j<len(string):
count=1
while j<len(string) and string[i]==string[j]:
j+=1
count+=1
if count>1:
count=list(str(count))
len_count=len(count)
string[i+1:i+1+len_count]=count
for k in range(i+1+len_count,j):
string.pop(i+1+len_count)
i=i+len_count
j=i+1
elif count==1:
i+=1
j=i+1
return string
lst=string_compression(['a','a','a','a','a','a','6','6'])
print(lst)
#def string_compression(string):
# i=0
# j=i+1
# count=1
# while j<len(string):
# if string[i]==string[j]:
# j+=1
# count+=1
# else:
#
#
# count=1
# while j<len(string) and string[i]==string[j]:
# j+=1
# count+=1
# count=list(str(count))
# len_count=len(count)
# string[i+1:i+1+len_count]=count
#
# for k in range(i+1+len_count,j):
# string.pop(k)
#
# i=i+len_count
# j=i+1
#
# return string
b=["b","l","6","4","2","W","2","&","d","3","@","D","2",".","3","8","3","U","V",">","J","2","k","H","2","=","l","[","7","a","2","'","<","[","2","y","V","l","2","'","$","E","`","v","k","E","2","t","5","=","2","0","C","a","l","3","r","R","M","2","c","3","A","2","S","9","4",")","2","\\","s","\\","2","y","W","3","J","4","6","2","<","2","E","u","e","9","9","4","R","8","?","F","3","&","4","f","%","2","2","3",")","3","J","p","|","D","3","s","t","V","2","?","^","2","S","3","4","h","*","|","2","b","2","a","3","r","4","J",".","^","2","~","g",":","3","(","4","4","w","7","C","?","=","d","L",":","0","2","c","w","6","{","2","t","k","3","&","3","h","j","3","0","3","l",";","5",".","3","%","1","3","l","9","?","3","t",">","E","N","2","@",">",".","2","I","a","4","B","7","2","{","o","2","-","+","4","o","2","}","B","2","r","3","q","4","3","9","W","5","'","3","g","J","(","4","t","2","?",";","g","3","0","]","3"]
a=["b","l","6","4","2","W","2","&","d","3","@","D","2",".","3","8","3","U","V",">","J","2","k","H","2","=","l","[","7","a","2","'","<","[","2","y","V","l","2","'","$","E","`","v","k","E","2","t","5","=","2","0","C","a","l","3","r","R","M","2","c","3","A","2","S","9","4",")","2","\\","s","\\","2","y","W","3","J","4","6","2","<","2","E","u","e","9","5","R","8","?","F","3","&","4","f","%","2","4",")","3","J","p","|","D","3","s","t","V","2","?","^","2","S","3","4","h","*","|","2","b","2","a","3","r","4","J",".","^","2","~","g",":","3","(","4","4","w","7","C","?","=","d","L",":","0","2","c","w","6","{","2","t","k","3","&","3","h","j","3","0","3","l",";","5",".","3","%","1","3","l","9","?","3","t",">","E","N","2","@",">",".","2","I","a","4","B","7","2","{","o","2","-","+","4","o","2","}","B","2","r","3","q","4","3","9","W","5","'","3","g","J","(","4","t","2","?",";","g","3","0","]","3"]
for i in range(len(a)):
if a[i]!=b[i]:
break