Skip to content

Commit 510a013

Browse files
authored
Merge pull request gzc426#124 from zero1997/master
24324
2 parents 5c521e2 + 69b4043 commit 510a013

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class Solution(object):
2+
def compress(self, chars):
3+
"""
4+
:type chars: List[str]
5+
:rtype: int
6+
"""
7+
8+
n = len(chars)
9+
cnt = 1;
10+
i = 0;
11+
for j in range(1, len(chars)+1):
12+
if j < n and chars[j-1] == chars[j]:
13+
cnt += 1;
14+
else:
15+
chars[i] = chars[j-1];
16+
i += 1;
17+
if cnt > 1:
18+
for m in str(cnt):
19+
chars[i] = m;
20+
i += 1;
21+
cnt = 1;
22+
return i;
23+
24+
25+
26+

0 commit comments

Comments
 (0)