Given a string s and a dictionary of strings wordDict, return true if s can be segmented into a space-separated sequence of one or more dictionary words.
Note that the same word in the dictionary may be reused multiple times in the segmentation.
翻譯
給定一個字符串 s 和一個字符串字典 wordDict,如果 s 可以分割成一個或多個字典單詞的空格分隔序列,則返回 true。
請注意,字典中的同一個詞可能會在分詞中重複使用多次。
範例
Exampele 1:
1 2 3
Input: s = "leetcode", wordDict = ["leet","code"] Output: true Explanation: Return true because "leetcode" can be segmented as "leet code".
Example 2:
1 2 3 4
Input: s = "applepenapple", wordDict = ["apple","pen"] Output: true Explanation: Return true because "applepenapple" can be segmented as "apple pen apple". Note that you are allowed to reuse a dictionary word.
Example 3:
1 2
Input: s = "catsandog", wordDict = ["cats","dog","sand","and","cat"] Output: false