79227539

Date: 2024-11-26 16:34:24
Score: 1
Natty:
Report link

A wrong cases offered in comments: s = ababac, t = abac.

According to the logic of the original code, the pointer s should move back by a certain position each time in the else{} statement, but the original code overlooks it.

I rewrite it like :

        if (*ptrT == *ptrS) {
            ptrT++;
        } else {
            ptrS -= (ptrT - t);
            ptrT = t;
        }
        ptrS++;

it works.

Reasons:
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Elliott T