WorkingI'm working on the prefix search problem and the problem is, given a set of words, for example words = ['a', 'apple', 'angle', 'angel', 'bat', 'bats']
, for any given prefix, find all matched words. For example, if input is ang
, return 'angle', 'angel'
, if no match, return an empty list []
.:
Given a set of words, for example
words = ['a', 'apple', 'angle', 'angel', 'bat', 'bats']
, for any given prefix, find all matched words. For example, if input isang
, return'angle', 'angel'
, if no match, return an empty list[]
.
Here is my code and anyAny advice on performance improvement in terms of algorithm time complexity (not sure if Trie Tree is the best solution), code bugs or general advice on code style is highly appreciated.
Source code in Python 2.7,