Word Break
Return whether s can be split into one or more dictionary words. A word may be reused.
Example 1
s = "campcamp"
wordDict = ["camp"]trueExplanation
Use camp twice because dictionary entries may be reused.
Example 2
s = "catsandog"
wordDict = ["cats","dog","sand","and","cat"]falseExplanation
cats/and leaves og, absent from the dictionary; no complete split exists.
Example 3
s = "abcd"
wordDict = ["a","bc","d"]trueExplanation
a/bc/d covers every character in order.
Constraints
- 1 <= len(s) <= 300
- Dictionary contains 1..1000 distinct nonempty lowercase words
- s is lowercase
Function contract
wordBreakArguments: json, jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 35 cases, on your device.
"campcamp"["camp"]