|
|
|
|
|
by ajuc
6215 days ago
|
|
I'll use radix tree for dictionary, to speed up testing. For words (son, sun, so, sunny) it would be: root -> S -> O -> .
\ \-> N -> .
\-> U -> N -> .
\-> N -> Y -> .
Then - for each character in given string I'll make pointer pointing at root of dictionary tree.Then in loop I would advance down each pointer in turn, until it's no longer possible to go down the tree, or the until the characters for given pointer ended. When no pointer can be advanced, the pointer that gives longest word is the best. |
|