answer
to store the concatenated words.dictionary
for quick look-up.words
list.dp
of length word.length + 1
and set dp[0]
to true.i
from 1 to word.length
, check if there exists an index j
such that dp[j]
is true and word.substring(j, i)
is in the dictionary
.j
exists, set dp[i]
to true.dp[word.length]
is true, add the word to the answer
list.answer
list after processing all words.