Given a string s and a list of strings wordDict, determine whether s can be segmented into a sequence of one or more dictionary words.
true
if such a segmentation exists, otherwise return
false
.
s
: a non-empty string
wordDict
: a list of non-empty strings
s
can be segmented.
s = "leetcode"
,
wordDict = ["leet", "code"]
→
true
s = "catsandog"
,
wordDict = ["cats","dog","sand","and","cat"]
→
false
1 <= len(s) <= 10^4
1 <= len(wordDict) <= 10^5
wordDict
can be large; aim for an efficient solution.