class Solution {
public:
int numSquares(int n) {
vector<int> f(n + 1, 0);
for(int i = 1; i <= n; i++){
int minnum = INT_MAX;
for(int j = 1; j * j <= i; ++j){
minnum = min(minnum, f[i - j * j]);
}
f[i] = minnum + 1;
}
return f[n];
}
};
Leecode279 完全平方数
最新推荐文章于 2024-11-09 21:51:15 发布