90. Word Break
Medium
Given a string texto and a list dicionario, determine whether it is possible to split the entire string into a sequence of words present in the dictionary. A dictionary word may be reused.
Example 1
Input: texto = "casanova", dicionario = ["casa", "no", "nova"]
Output: true
Explanation: The split "casa" + "no" + "va" does not work, but "casa" + "nova" works.
Example 2
Input: texto = "abac", dicionario = ["aba", "ac"]
Output: false
Constraints
- 0 <= texto.length <= 300
- 1 <= dicionario.length <= 1000
- The words and the string contain lowercase letters.
Dynamic programmingStringsHash map
Saved in this browser
Caso 1
texto =
"casanova"
dicionario =
["casa","nova"]
Expected =
true
Caso 2
texto =
"abac"
dicionario =
["aba","ac"]
Expected =
false
Run checks these 2 cases. Submit runs all 6, including hidden ones.