34. Word Break

Medium · String

Given a string s and a list of dictionary words, determine whether s can be segmented into a sequence of one or more words from the dictionary. Each word in the dictionary may be used multiple times. Return true if s can be fully segmented using dictionary words, otherwise return false.

Input: An array [s, wordDict] where s is a string and wordDict is an array of dictionary words.

Output: Return a boolean — true if s can be segmented into dictionary words, false otherwise.

Examples

Example 1
Input: ["leetcode", ["leet","code"]]
Output: true
Explanation: "leet" + "code"
Example 2
Input: ["catsandog", ["cats","dog","sand","and","cat"]]
Output: false
Explanation: No valid segmentation

Constraints