3 ms·
Are you sure your algorithm is O(n)? It seems like in the worst case (if you have strings with lots of repeated letters like "aaaaaaaaaaaaaax" and "yaaaaaaaaaa
by mbrubeck 17y ago
Are you sure your algorithm is O(n)? It seems like in the worst case (if you have strings with lots of repeated letters like "aaaaaaaaaaaaaax" and "yaaaaaaaaaaaaaa" the inner loop may run O(n) times with O(n) complexity, leading to O(n^2) total performance.