首页
mac
it
登录
6mi
u
盘
搜
搜 索
it
【攻克力扣200题--31】279. 完全平方数
【攻克力扣200题--31】279. 完全平方数
mac
2024-07-04
58
dp,动态方程:dp[i]=Math.min(dp[i],dp[i-j*j]+1);
var numSquares = function(n) { const dp=[...Array(n+1)].map(_=>0); for(let i=1;i<=n;i++){ dp[i]=i;//最坏的情况就是由若干个1构成; for(let j=0;i-j*j>=0;j++) dp[i]=Math.min(dp[i],dp[i-j*j]+1); } return dp[n]; };
转载请注明原文地址: https://mac.8miu.com/read-494352.html
最新回复
(
0
)