139 Word Break
139. Word Break
1. Question
Given a non-empty strings and a dictionary wordDict containing a list of non-empty words, determine if scan be segmented into a space-separated sequence of one or more dictionary words. You may assume the dictionary does not contain duplicate words.
For example, given
s="leetcode"
,
dict=["leet", "code"]
.
Return true because"leetcode"
can be segmented as"leet code"
.
2. Implementation
(1) DFS + Memoinzation
(2) DP
3. Time & Space Complexity
DFS + Memoinzation: 时间复杂度O(n^2), 空间复杂度O(n)
DP: 时间复杂度O(n^2), 空间复杂度O(n)
Last updated