We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a09bcc7 commit 5f37829Copy full SHA for 5f37829
2018.11.29-leetcode443/Ostrichcrab.md
@@ -0,0 +1,37 @@
1
+```
2
+class Solution {
3
+public:
4
+ int compress(vector<char>& chars) {
5
+ int len = chars.size();
6
+ if(len == 1) return chars.size();
7
+ chars.push_back(' ');//统一一下
8
+ len++;
9
+ int cnt = 1;
10
+ char pre = ' ';
11
+ pre = chars[0];
12
+ for(int i = 1; i < len; i++){
13
+ if(chars[i] == pre){
14
+ chars.erase(chars.begin()+i);
15
+ i--;
16
+ len--;
17
+ cnt++;
18
+ } else if(cnt>1){
19
+ stringstream ss;
20
+ string s;
21
+ ss<<cnt;
22
+ ss>>s;
23
+ pre=chars[i];
24
+ for(int j = 0; j < s.size(); j++){
25
+ chars.insert(chars.begin()+i,s[j]);
26
+ i++;
27
28
+ }
29
+ cnt=1;
30
31
+ pre = chars[i];
32
33
+ chars.pop_back();//最后去除
34
+ return chars.size();
35
36
+};
37
0 commit comments