you can build the minimal DFA (that can be done in O(n²) or O(n³), not sure...)
Actually that can be done in O(n lg n) using Hopcroft's Algorithm, but it's not a well known or particularly easy algorithm. See Hopcroft's 1971 paper, though even the academics find it a bit dense, which led Gries to write a paper called Describing an algorithm by Hopcroft a year later. Unfortunately the latter is not freely available online.
All this is surely overboard for the poster's original question, I just wanted to share this tidbit since it's not easy to come by.