PIXELBANKv8.2.1
Menu

Word Break

Given a string s and a word dictionary, return True if s can be segmented into space-separated sequence of dictionary words.

Example:

Input:
leetcode
leet,code
Output:
True
Reasoning:
  • The input string s is "leetcode" and the word dictionary contains "leet" and "code".
  • We attempt to segment s into a sequence of dictionary words, starting with "leet" which matches the first 4 characters of s.
  • The remaining characters "code" also match a word in the dictionary.
  • Since the entire string s can be segmented into a sequence of dictionary words ("leet" and "code"), the output is True.

Constraints:

  • 1 <= len(s) <= 300
  • 1 <= len(wordDict) <= 1000
  • 1 <= len(wordDict[i]) <= 20
Editor

Test Results

0/0
Run code to see test results.