I had this question on an Algorithms test yesterday, and I can\'t figure out the answer. It is driving me absolutely crazy, because it was worth about 40 points. I figure
An adaptation of the Rabin-Karp algorithm could be possible for you. Its complexity is 0(n) so it could help you.
Take a look http://en.wikipedia.org/wiki/Rabin-Karp_string_search_algorithm