当前位置:网站首页>279. perfect square
279. perfect square
2022-06-12 18:17:00 【qq_ forty-eight million two hundred and thirty thousand four hu】
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 .
-------------------------------------------------------------------------------------------------------------------
Using dynamic planning and dual thinking for Cycle to solve 、
class Solution {
public int numSquares(int n) {
int[]res=new int[n+1];
for(int i=1;i<=n;i++){
int minn=Integer.MAX_VALUE;
for(int j=1;j*j<=i;j++){
minn=Math.min(minn,res[i-j*j]);
}
res[i]=minn+1;
}
return res[n];
}
}
边栏推荐
猜你喜欢

USB to serial port - maximum peak serial port baud rate vs maximum continuous communication baud rate

PHP:Fatal error: Allowed memory size of 262144 bytes exhausted (tried to allocat

企业架构的第一性原理

C#简单介绍

VirtualLab基础实验教程-4.单缝衍射

SSM integrates FreeMarker and common syntax

Queue priority of message queue practice

Virtual Lab Basic Experiment tutoriel - 4. Diffraction à fente unique

VirtualLab basic experiment tutorial -6 Blazed grating

Esp32-c3 esp-idf configuring smartconfig and SNTP to obtain network time
随机推荐
Make good use of IDE, speed up R & D efficiency by 100%
This shift, I still have to go
General differences between SQL server versions released by Microsoft in different periods so far, for reference
An easy-to-use IDE for small programs
C language practice (4) -- multiplication and division of large numbers
Applet and app are owned at the same time? A technical scheme with both
Leetcode491 increasing subsequence
静态内存分配和动态内存分配小结
torch. New usage of where (old but ignored usage)
torch.where的新用法(很老但是大家忽略的用法)
Relationship between resolution and line field synchronization signal
Reconstruction -- sort out and decompose the inheritance system
JS中的字符串(含leetcode例题)<持续更新~>
Vant3+ts dropdownmenu drop-down menu, multi data can be scrolled
VirtualLab基础实验教程-4.单缝衍射
Gospel of audio and video developers, rapid integration of AI dubbing capability
PHP:Fatal error: Allowed memory size of 262144 bytes exhausted (tried to allocat
js二分法
Extracting strings with grep awk
用好IDE,研发效能提速100%