3 ms·
Pretty much something along these lines, except it's also required that both pattern and s end at the same time for a full match (this complicates the base case
by m0zg 8y ago
Pretty much something along these lines, except it's also required that both pattern and s end at the same time for a full match (this complicates the base case a tiny bit). The C/C++ solution looks more elegant because you can use pointers. Note that this particular version requires no prior knowledge of the algorithm and can be solved on the spot fairly easily.