|
| 1 | +<h2><ahref="https://leetcode.com/problems/word-break/">139. Word Break</a></h2><h3>Medium</h3><hr><p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> |
| 2 | + |
| 3 | +<p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmentation.</p> |
| 4 | + |
| 5 | +<p> </p> |
| 6 | +<p><strongclass="example">Example 1:</strong></p> |
| 7 | + |
| 8 | +<pre> |
| 9 | +<strong>Input:</strong> s ="leetcode", wordDict = ["leet","code"] |
| 10 | +<strong>Output:</strong> true |
| 11 | +<strong>Explanation:</strong> Return true because"leetcode" can be segmented as"leet code". |
| 12 | +</pre> |
| 13 | + |
| 14 | +<p><strongclass="example">Example 2:</strong></p> |
| 15 | + |
| 16 | +<pre> |
| 17 | +<strong>Input:</strong> s ="applepenapple", wordDict = ["apple","pen"] |
| 18 | +<strong>Output:</strong> true |
| 19 | +<strong>Explanation:</strong> Return true because"applepenapple" can be segmented as"apple pen apple". |
| 20 | +Note that you are allowed to reuse a dictionary word. |
| 21 | +</pre> |
| 22 | + |
| 23 | +<p><strongclass="example">Example 3:</strong></p> |
| 24 | + |
| 25 | +<pre> |
| 26 | +<strong>Input:</strong> s ="catsandog", wordDict = ["cats","dog","sand","and","cat"] |
| 27 | +<strong>Output:</strong> false |
| 28 | +</pre> |
| 29 | + |
| 30 | +<p> </p> |
| 31 | +<p><strong>Constraints:</strong></p> |
| 32 | + |
| 33 | +<ul> |
| 34 | +<li><code>1 <= s.length <= 300</code></li> |
| 35 | +<li><code>1 <= wordDict.length <= 1000</code></li> |
| 36 | +<li><code>1 <= wordDict[i].length <= 20</code></li> |
| 37 | +<li><code>s</code> and <code>wordDict[i]</code> consist of only lowercase English letters.</li> |
| 38 | +<li>All the strings of <code>wordDict</code> are <strong>unique</strong>.</li> |
| 39 | +</ul> |