#include <algorithm>
class Solution {
public:
int compress(vector<char>& chars) {
int m = chars.size();
int i = 0, j = 1, tmp= 0;
int length;
while (i < m && j < m){
while (j < m && chars[j] == chars[i]) {
j++;
}
tmp = j;
length = j - i;
while (--j > i){
if (length != 0){
chars[j] = length % 10 + '0';
length = length / 10;
continue;
}
chars[j] = '"';
}
i = tmp;
j = tmp+1;
}
chars.erase(remove(chars.begin(), chars.end(), '"'), chars.end());
return chars.size();
}
};
10-26
2890
06-09
918
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交