Skip to content

Commit a2f9fca

Browse files
authored
Merge pull request gzc426#187 from FFFro/patch-1
Create FFFro.md
2 parents 1050270 + 409fcb7 commit a2f9fca

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

2018.11.29-leetcode443/FFFro.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public int compress(char[] chars) {
3+
int count = 1;
4+
int index = 0;
5+
for (int i = 0; i < chars.length; i++) {
6+
if (i == chars.length-1 || chars[i] != chars[i+1]) {
7+
chars[index++] = chars[i];
8+
if (count > 1) {
9+
String a = String.valueOf(count);
10+
for (int k = 0; k < a.length(); k++) {
11+
chars[index++] = a.charAt(k);
12+
}
13+
}
14+
count = 1;
15+
} else {
16+
count++;
17+
}
18+
}
19+
return index;
20+
}
21+
}

0 commit comments

Comments
 (0)