There was an error while loading. Please reload this page.
1 parent b89152b commit 4412370Copy full SHA for 4412370
10 October LeetCode Challenge 2021/14_pefectSquares.cpp
@@ -0,0 +1,18 @@
1
+class Solution {
2
+public:
3
+ int numSquares(int n) {
4
+ //vector for updating the dp array/values
5
+ vector<int> dp(n+1,INT_MAX);
6
+ //base case
7
+ dp[0]=0;
8
+ int count = 1;
9
+ while(count*count <= n) {
10
+ int sq = count*count;
11
+ for(int i = sq; i < n+1; i++) {
12
+ dp[i] = min(dp[i-sq] + 1,dp[i]);
13
+ }
14
+ count++;
15
16
+ return dp[n];
17
18
+};
0 commit comments