Approach hintTry it first, then revealHide
Let dp[i] be true when the prefix of length i can be segmented. It holds if some j < i has dp[j] true and s[j..i) is a dictionary word, which a hash set checks quickly.
Let dp[i] be true when the prefix of length i can be segmented. It holds if some j < i has dp[j] true and s[j..i) is a dictionary word, which a hash set checks quickly.