2 ms·
You can use an inner loop to skip over removable chars in the source string but I didn't think that was n^2. (Code below for reference.) Am I wrong that my solu
by philwelch 16y ago
You can use an inner loop to skip over removable chars in the source string but I didn't think that was n^2. (Code below for reference.) Am I wrong that my solution is n, or is there another obvious n^2 algorithm?
void condense_by_removing( char *z_terminated , char char_to_remove)
{
char * sp;
char * dp;
sp = dp = z_terminated;
while (*sp != '\0') {
while (*sp == char_to_remove){
sp++;
}
*dp = *sp;
dp++;
sp++;
}
*dp = *sp;
}