words
array.text
string as the starting index i
.
p
to the root of the trie.j
, check if there is an edge from p
labeled with text[j]
.p
to the corresponding child node.p
is marked as a word, add the index pair [i, j]
to the result list.i+1
.