当前位置:网站首页>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];
}
}
边栏推荐
- Opencvshare4 and vs2019 configuration
- The precision of C language printf output floating point numbers
- Hstack, vstack and dstack in numpy
- Opencv 9 resize size change rotate rotate blur mean (blur)
- [reading point paper] yolo9000:better, faster, stronger, (yolov2), integrating various methods to improve the idea of map and wordtree data fusion
- How can intelligent safe power distribution devices reduce the occurrence of electrical fire accidents?
- redis
- Area of basic exercise circle ※
- C language compressed string is saved to binary file, and the compressed string is read from binary file and decompressed.
- Basic exercise of test questions decimal to hexadecimal
猜你喜欢

Paper reading - group normalization

Stm32f4 DMA Da sine wave generator keil5 Hal library cubemx

05 tabBar导航栏功能
![Leetcode 473. 火柴拼正方形 [暴力+剪枝]](/img/3a/975b91dd785e341c561804175b6439.png)
Leetcode 473. 火柴拼正方形 [暴力+剪枝]

Open source video recolor code

Laravel permission export

Armv8-m (Cortex-M) TrustZone summary and introduction

4.11 introduction to firmware image package

Opencv 15 face recognition and eye recognition

Graph theory, tree based concept
随机推荐
How can intelligent safe power distribution devices reduce the occurrence of electrical fire accidents?
C # illustrated tutorial (Fourth Edition) chapter7-7.2 accessing inherited members
[reading papers] deepface: closing the gap to human level performance in face verification. Deep learning starts with the face
Number of special palindromes in basic exercise of test questions
01 initial knowledge of wechat applet
An image is word 16x16 words: transformers for image recognition at scale
04路由跳转并携带参数
Understand HMM
Yovo3 and yovo3 tiny structure diagram
[reading point paper] yolo9000:better, faster, stronger, (yolov2), integrating various methods to improve the idea of map and wordtree data fusion
Branch and bound method, example sorting
Flow chart of interrupt process
Leetcode 450. Delete node in binary search tree [binary search tree]
01 初识微信小程序
Laptop touch pad operation
[reading papers] deep learning face representation by joint identification verification, deep learning applied to optimization problems, deepid2
How to learn to understand Matplotlib instead of simple code reuse
重定向设置参数-RedirectAttributes
[analysis notes] source code analysis of siliconlabs efr32bg22 Bluetooth mesh sensorclient
[pytorch] kaggle image classification competition arcface + bounding box code learning