TRIE solution.  50 seconds too slow though