← problems
#139

Word Break

MediumDynamic Programming

Given a string s and a dictionary of strings wordDict, return true if s can be segmented into a space-separated sequence of one or more dictionary words.

The same dictionary word may be reused multiple times.

Example

s = "leetcode", wordDict = ["leet", "code"]  => true
s = "catsandog", wordDict = ["cats","dog","sand","and","cat"]  => false
Implement
function WordBreak(s: string, wordDict: string[]) -> bool

Found a bug? Or annoyed about something in the language? Tell us.

loading editor…