← 返回 bytedance 的题目列表Word Construction from Dictionary
类型:online_judge
Given a target word and a dictionary, design an algorithm to determine if the target word can be constructed by using the words in the dictionary. Words in the dictionary can be reused.
Input:
A string target representing the target word.
A set wordDict containing the words available to construct the target word.
Output:
Return a boolean indicating whether the target word can be constructed by using the words in the dictionary.
Example:
Input: target = "leetcode", wordDict = ["leet", "code"]
Output: true
Input: target = "applepenapple", wordDict = ["apple", "pen"]
Output: true
Input: target = "catsandog", wordDict = ["cats", "dog", "sand", "and", "cat"]
Output: false
Constraints:
1 <= target.length <= 300
1 <= wordDict.length <= 1000
1 <= wordDict[i].length <= 100
target and wordDict[i] consist of lowercase English letters only.
Example
Input
leetcode
leet code