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]: 和为 i 的完全平方数的最少数量
dp[i]
dp[i] = Math.min(dp[i], i - j * j + 1)
dp[i] 可以由 dp[i - j * j] + 1 推出,取二者中较小者。
dp[i - j * j] + 1
dp[0] = 0
const numSquares = function(n) { const dp = new Array(n + 1).fill(0) for (let i = 1; i <= n; i++) { dp[i] = i for (let j = 1; i - j * j >=0; j++) { dp[i] = Math.min(dp[i], dp[i - j * j] + 1) } } return dp[n] }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
原题链接
状态定义
dp[i]
: 和为 i 的完全平方数的最少数量状态转移方程
dp[i] = Math.min(dp[i], i - j * j + 1)
dp[i]
可以由dp[i - j * j] + 1
推出,取二者中较小者。初始化
dp[0] = 0
The text was updated successfully, but these errors were encountered: