Skip to content

Commit 087ef97

Browse files
authored
Create 。。。.md
1 parent ffc763a commit 087ef97

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

2018.11.29-leetcode443/。。。.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
public int compress(char[] chars) {
2+
int cur = 1;//压缩后字符串的长度
3+
int repet = 1;
4+
for (int i = 1; i < chars.length; i++){
5+
if (chars[i-1] == chars[i]) {//出现连续重复的字符串
6+
repet++;
7+
}else {
8+
if (repet!=1){
9+
char[] num = String.valueOf(repet).toCharArray();
10+
for (int j = 0; j < num.length; j++){
11+
chars[cur++] = num[j];
12+
}
13+
repet=1;
14+
}
15+
chars[cur++] = chars[i];
16+
}
17+
}
18+
if (repet!=1){
19+
char[] num = String.valueOf(repet).toCharArray();
20+
for (int j = 0; j < num.length; j++){
21+
chars[cur++] = num[j];
22+
}
23+
}
24+
Log.d(new String(chars));
25+
return cur;
26+
}

0 commit comments

Comments
 (0)