2 ms·
On the other hand, the first one has a bug when the length is 1, which the second one fixes... but of course you could fix it without allocating memory either.
by userbinator 8y ago
On the other hand, the first one has a bug when the length is 1, which the second one fixes... but of course you could fix it without allocating memory either.
Relatedly, in image and video processing the (literal) "edge cases" are sometimes handled by allocating the buffer slightly larger in the first place, so that filtering operations (which are very similar to that example) don't run off the edge. Maybe the real lesson here is "think ahead"?