Medium · Strings

Word break

Given a string s and a list of dictionary words wordDict, return true if s can be split into a sequence of dictionary words (a word may be used more than once), otherwise false; the empty string needs no words and returns true.

Examples

Example 1

{
  "s": "rainbow",
  "wordDict": ["rain", "bow"]
}

Output: true

Example 2

{
  "s": "applepen",
  "wordDict": ["apple", "pen"]
}

Output: true

Rebuild it in the studio

Open every published interview problem, solution, scene, and memory room free, with no account.

More Strings problems