[LeetCode C++实现]443. String Compression
刷完上一道题目字符串压缩,看到leetcode中的443题,基本上与字符串压缩这道题一致。
class Solution {
public:
int compress(vector<char>& chars) {
int n = chars.size();
//location to write and character count
int loc = 0,cnt = 1;
if(n < 2) return n;
for(int i = 1 ;i < n ;i++)
{
if(chars[i] == chars[i-1])
{
cnt++;
}else{......