当前位置:网站首页>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];
}
}
边栏推荐
- 03 认识第一个view组件
- too old resource version,Code:410
- An image is word 16x16 words: transformers for image recognition at scale
- Opencvsharp4 handwriting recognition
- Leetcode 926. Flip string to monotonically increasing [prefix and]
- For loop instead of while loop - for loop instead of while loop
- Chapter7-10_ Deep Learning for Question Answering (1/2)
- The fastest empty string comparison method C code
- Use of OpenCV 11 kmeans clustering
- Exam23 named windows and simplified paths, grayscale conversion
猜你喜欢

Queuing theory, game theory, analytic hierarchy process

04路由跳转并携带参数

Mbedtls migration experience

Matlab: find the inner angle of n-sided concave polygon
![[reading papers] deepface: closing the gap to human level performance in face verification. Deep learning starts with the face](/img/e4/a25716ae7aa8bdea64eb9314ca2cc7.jpg)
[reading papers] deepface: closing the gap to human level performance in face verification. Deep learning starts with the face

Thinking back from the eight queens' question

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%

0- blog notes guide directory (all)

Why does it feel that most papers still use RESNET as the backbone network rather than densenet?

Image table solid line and dashed line detection
随机推荐
Paper reading - beat tracking by dynamic programming
Branch and bound method, example sorting
Mbedtls migration experience
Use of OpenCV 11 kmeans clustering
Easydl related documents and codes
Resource arrangement
Armv8-m learning notes - getting started
Image table solid line and dashed line detection
Opencvsharp4 pixel read / write and memory structure of color image and gray image
微信云开发粗糙理解
Opencv 17 face recognition
ROS learning-6 detailed explanation of publisher programming syntax
[keras] train py
Chapter7-12_ Controllable Chatbot
How can intelligent safe power distribution devices reduce the occurrence of electrical fire accidents?
Classification and summary of system registers in aarch64 architecture of armv8/arnv9
Graph theory, tree based concept
[pytorch] kaggle large image dataset data analysis + visualization
Basic exercises of test questions Fibonacci series
01 初识微信小程序