Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Word Break

XPChallenge Points: 20
levelLevel: Medium

You are given a string s and a list of strings wordDict representing a dictionary.
Your task is to determine whether s can be segmented into a space-separated sequence of one or more valid words from the dictionary.
The same word in the dictionary may be used multiple times in the segmentation.
Return true if the string can be segmented, otherwise return false.

Example 1:

Input: s = "programminghero" wordDict = ["program", "ming", "hero"]

Output: true

Example 2:

Input: s = "learnpythonfast" wordDict = ["learn", "python", "fast", "code"]

Output: true

Example 3:

Input: s = "helloleetcode" wordDict = ["hello", "leet", "code"]

Output: false

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result