Skip to content

Commit d779cb3

Browse files
authored
Merge pull request gzc426#230 from zjukk/patch-8
Create zjukk.md
2 parents c28ff43 + 2a638ee commit d779cb3

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

2018.11.29-leetcode443/zjukk.md

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

0 commit comments

Comments
 (0)