We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
原题链接
dp[i]: 字符串 s 的前 i 个字符子串 s[0..i-1] 是否由单词表组成。
dp[i]
s[0..i-1]
dp[i] = dp[j] && check(s[j..i-1])
[0..j-1]
[j, i-1]
check(s[j..i-1])
s[j..i-1]
状态转移方程需要满足:
dp[j]
dp[0] = true,空串且合法。
const wordBreak = function(s, wordDict){ const wordDictSet = new Set(wordDict) const len = s.length const dp = new Array(len + 1).fill(false) dp[0] = true for (let i = 1; i <= len; i++) { for (let j = i - 1; j >= 0; j--) { const suffix = s.slice(j, i) if (wordDictSet.has(suffix) && dp[j]) { dp[i] = true break } } } return dp[len] }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
原题链接
状态定义
dp[i]
: 字符串 s 的前 i 个字符子串s[0..i-1]
是否由单词表组成。状态转移方程
dp[i] = dp[j] && check(s[j..i-1])
[0..j-1]
(dp[j]) 和[j, i-1]
。check(s[j..i-1])
:代表子串s[j..i-1]
是否出现在字典中。状态转移方程需要满足:
dp[j]
为真s[j..i-1]
是否在单词表中初始化
dp[0] = true,空串且合法。
The text was updated successfully, but these errors were encountered: