← 返回 amazon 的题目列表Variation of Word Break
类型:online_judge
amazon
Given a non-empty string s and a non-empty dictionary dict containing non-empty strings, determine if s can be segmented into a space-separated sequence of one or more dictionary words. Each word in the dictionary can be used multiple times.
Input:
A string s.
An array of strings dict.
Output:
Return true if s can be segmented into dictionary words.
Otherwise, return false.
Constraints:
The total length of s is at most 1000.
Test Cases:
Input: s = "leetcode", dict = ["leet", "code"] Output: true
Input: s = "applepenapple", dict = ["apple", "pen"] Output: true
Input: s = "catsandog", dict = ["cats", "dog", "sand", "and", "cat"] Output: false
Example
Input
leetcode
leet code