Word break and all possible sentences
Given a non-empty string text
and a list dictWords
containing a set of non-empty words, check if text
can be split into a sequence of one or more dictionary words separated by spaces.
Note:
Example 1: Input: text = "programming", dictWords = ["pro", "gram", "ming"] Output: true Explanation: "programming" can be segmented as "pro gram ming". Example 2: Input: text = "appletreeapple", dictWords = ["apple", "tree"] Output: true Explanation: "appletreeapple" can be segmented as "apple tree apple". Note that dictionary words can be reused. Example 3: Input: text = "catsanddogs", dictWords = ["cats", "dog", "sand", "and", "cat"] Output: false
text
≤ 300dictWords
≤ 1000dictWords
≤ 20