Given a string s and a dictionary wordDict, return true if s can be segmented into a space-separated sequence of one or more dictionary words. This is a classic state-transition DP problem on prefixes.
s = string, wordDict = list of words
true if s can be segmented into dictionary words
Example 1:
Input:
s = "leetcode" wordDict = ["leet","code"]
Output:
true
Explanation:
leetcode = leet + code.
Example 2:
Input:
s = "applepenapple" wordDict = ["apple","pen"]
Output:
true
Explanation:
apple + pen + apple is valid.