Skip to content

Commit a367d71

Browse files
authored
Create string-compression-iii.py
1 parent 8aa8e0c commit a367d71

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Python/string-compression-iii.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
# string
5+
class Solution(object):
6+
def compressedString(self, word):
7+
"""
8+
:type word: str
9+
:rtype: str
10+
"""
11+
result = []
12+
cnt = 0
13+
for i in xrange(len(word)):
14+
cnt += 1
15+
if cnt == 9 or (i+1 == len(word) or word[i+1] != word[i]):
16+
result.append("%s%s" % (cnt, word[i]))
17+
cnt = 0
18+
return "".join(result)

0 commit comments

Comments
 (0)