CheezItMan / Word-break

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Word Break

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

Note that the same word in the dictionary may be reused multiple times in the segmentation.

Example 1:

Input: s = "leetcode", word_dict = ["leet", "code"]

Output: True

Explanation:

We return True because "leetcode" can be segmented as "leet code".

Example 2:

Input: s = "applepenapple", word_dict = ["apple", "pen"]

Output: True

Explanation:

We return True because "applepenapple" can be segmented as "apple pen apple". Note that "apple" can be used twice.

Example 3:

Input: s = "catsandog", `word_dict = ["cats", "dog", "sand", "and", "cat"]``

Output: False

Explanation:

We return False because "catsandog" cannot be segmented with the words provided in the dictionary without overlap.

This exercise was taken from: Leetcode: Word Break

About


Languages

Language:Python 97.2%Language:C 2.6%Language:Shell 0.2%Language:Nix 0.0%