双指针
class Solution
{
public:
string compressString(string S)
{
if (S.size() == 0) return "";
int i = 0;
int j = 0;
string ans = "";
while (i < S.size())
{
j = i;
while (j < S.size() && S[j] == S[i])
{
j++;
}
ans += S[i];
ans += to_string(j-i);
i = j;
}
return ans.size() >= S.size() ? S : ans;
}
};