← All problems
Word Break
HardDP
Given a string s and a dictionary of words, return true if s can be segmented into a space-separated sequence of dictionary words.
Examples
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
Hints
Solution
Language:
Loading editor…
Output0 lines
Run your code to see output here.
Click Run all tests to check your solution against 3 test cases.