[LeetCode] 139. Word Break


Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can 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".

給一個字串 跟 一本字典 請問字串是否可以被字典分割

這題可以說是 一維 DP 的經典題

宣告一個 list,  list[2] 表示 le 是否可以被分割

https://www.youtube.com/watch?v=WepWFGxiwRs




詳細拆解,

留言