当前位置:网站首页>Perfect square
Perfect square
2022-06-13 02:33:00 【Prodigal son's private dishes】
subject :
Give you an integer n , return And for n The minimum number of complete squares of .
Complete square It's an integer , Its value is equal to the square of another integer ; let me put it another way , Its value is equal to the product of the self multiplication of an integer . for example ,1、4、9 and 16 They're all perfect squares , and 3 and 11 No .
Example 1:
Input :n = 12
Output :3
explain :12 = 4 + 4 + 4Example 2:
Input :n = 13
Output :2
explain :13 = 4 + 9
Code :
class Solution {
public int numSquares(int n) {
int max = Integer.MAX_VALUE;
int[] dp = new int[n+1];
for(int j = 0; j <= n; j++){
dp[j] = max;
}
dp[0] = 0;
for(int i = 0; i * i <= n; i++){
for(int j = i * i; j <= n; j++){
if(dp[j - i * i] != max){
dp[j] = Math.min(dp[j], dp[j- i *i] +1);
}
}
}
return dp[n];
}
}
边栏推荐
- Paper reading - jukebox: a generic model for music
- [reading papers] deep learning face representation from predicting 10000 classes. deepID
- Leetcode 473. Match to square [violence + pruning]
- The precision of C language printf output floating point numbers
- ROS learning -5 how function packs with the same name work (workspace coverage)
- Leetcode 450. 删除二叉搜索树中的节点 [二叉搜索树]
- regular expression
- redis 多个服务器共用一个
- Flow chart of interrupt process
- [reading point paper] deeplobv3 rethinking atlas revolution for semantic image segmentation ASPP
猜你喜欢

Understand speech denoising

Jump model between mirrors

Fast Color Segementation

Huffman tree and its application

Yovo3 and yovo3 tiny structure diagram

Opencv 15 face recognition and eye recognition
![Leetcode 450. 删除二叉搜索树中的节点 [二叉搜索树]](/img/39/d5c4d424a160635791c4645d6f2e10.png)
Leetcode 450. 删除二叉搜索树中的节点 [二叉搜索树]

Laravel permission export

Paipai loan parent company Xinye quarterly report diagram: revenue of RMB 2.4 billion, net profit of RMB 530million, a year-on-year decrease of 10%

ROS learning-8 pit for custom action programming
随机推荐
Is space time attention all you need for video understanding?
Jump model between mirrors
redis 多个服务器共用一个
Classification and summary of system registers in aarch64 architecture of armv8/arnv9
02 优化微信开发者工具默认的结构
L1 regularization and its sparsity
1000粉丝啦~
Graph theory, tree based concept
How to destroy a fragment- How to destroy Fragment?
Opencvsharp4 handwriting recognition
Thesis reading - autovc: zero shot voice style transfer with only autoencoder loss
Easydl related documents and codes
Use of OpenCV 11 kmeans clustering
Leetcode 926. Flip string to monotonically increasing [prefix and]
1000 fans ~
Matlab: obtain the figure edge contour and divide the figure n equally
Gadgets: color based video and image cutting
[pytorch] kaggle image classification competition arcface + bounding box code learning
Opencv 15 face recognition and eye recognition
Mean Value Coordinates