Leetcode - Strings | Substring
139. Word Break[M]
https://leetcode.com/problems/word-break/
Description
Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words.
Note:
- The same word in the dictionary may be reused multiple times in the segmentation.
- You may assume the dictionary does not contain duplicate words.
Example 1:
1 | Input: s = "leetcode", wordDict = ["leet", "code"] |
Example 2:
1 | Input: s = "applepenapple", wordDict = ["apple", "pen"] |
Example 3:
1 | Input: s = "catsandog", wordDict = ["cats", "dog", "sand", "and", "cat"] |
Solution
1 | class Solution: |
140. Word Break II[H]
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. Return all such possible sentences.
Note:
- The same word in the dictionary may be reused multiple times in the segmentation.
- You may assume the dictionary does not contain duplicate words.
Example 1:
1 | Input: |
Example 2:
1 | Input: |
Example 3:
1 | Input: |
Solution
https://discuss.leetcode.com/topic/12997/11ms-c-solution-concise
1 | class Solution: |
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.
Comment





