Skip to content

Commit 752e83f

Browse files
authored
Merge pull request gzc426#146 from Jerring/master
1
2 parents 256c015 + 91e6dd7 commit 752e83f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

2018.11.29-leetcode443/TheRocket.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
```java
2+
class Solution {
3+
public int compress(char[] chars) {
4+
int n = 0;
5+
int i = 0;
6+
while (i < chars.length){
7+
chars[n++] = chars[i++];
8+
int cnt = 1;
9+
while (i < chars.length && chars[i] == chars[i - 1]) {
10+
++i;
11+
++cnt;
12+
}
13+
if (cnt > 1) {
14+
for (char c : Integer.toString(cnt).toCharArray()) {
15+
chars[n++] = c;
16+
}
17+
}
18+
}
19+
return n;
20+
}
21+
}
22+
```

0 commit comments

Comments
 (0)