Word Break - All Possible Sentences
Given a non-empty string text
and a list of non-empty words called dictList
, insert spaces into text
to form sentences where each word is contained in dictList
. Return all such possible sentences.
Note:
text = "dogsandcat" dictList = ["dog", "dogs", "and", "cat"] Output: [ "dogs and cat", "dog sand cat" ]
text = "applepenapple" dictList = ["apple", "pen", "applepen"] Output: [ "apple pen apple", "applepen apple" ]
text = "catsandbat" dictList = ["cats", "dog", "sand", "and", "cat", "bat"] Output: [ "cats and bat", "cat sand bat" ]
text
≤ 25dictList
≤ 20text
consist of lowercase English letters only.