wordDict
into a set words
for constant-time lookups.0
and a set seen
to keep track of visited nodes.start
.start
equals the length of s
, return true
.start + 1
to the length of s
:
end
, if it has not been visited and the substring s[start:end]
is in words
, enqueue end
and mark it as seen.false
.