moonlightshadow123
6/25/2017 - 2:33 PM

140. Word Break II

  1. Word Break II

https://leetcode.com/problems/word-break-ii/#/description

Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, add spaces in s to construct a sentence where each word is a valid dictionary word. You may assume the dictionary does not contain duplicate words.

Return all such possible sentences.

For example, given s = "catsanddog", dict = ["cat", "cats", "and", "sand", "dog"].

A solution is ["cats and dog", "cat sand dog"].