O(n) Solution Erase Function


#1

string Solution::solve(string a, int b) {

string c;
int count = 1;
int i;
for( i=0;i<a.size()-1;i++){
    c+=a[i];
    if(count==b){
        count=1;
        c.erase(c.end()-b,c.end());
    }
    if(a[i]==a[i+1]){
        count++;
    }
    
}
c+=a[i];
if(count==b){
        c.erase(c.end()-b,c.end());
    }
return c;

}