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.
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"] |
s = “catsandog”
wordDict = [“cats”, “dog”, “sand”, “and”, “cat”]
找字頭符合,在字典標為True.
1 | # T: O(nˆ2), S: O(n) |
如果你覺得這篇文章很棒,請你不吝點讚 (゚∀゚)