Skip to content

Commit 99ca0d7

Browse files
committed
Solve 279 with C++(memorization).
1 parent 87430d0 commit 99ca0d7

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Author: illuz <iilluzen[at]gmail.com>
3+
* File: AC_memorization_nsqrtn.cpp
4+
* Create Date: 2015-10-26 12:24:30
5+
* Descripton:
6+
*/
7+
8+
#include <bits/stdc++.h>
9+
10+
using namespace std;
11+
const int N = 0;
12+
13+
class Solution {
14+
public:
15+
int numSquares(int n) {
16+
vector<int> result(n + 1);
17+
for (int i = 1; i <= n; ++i) {
18+
int best = i;
19+
for (int j = 1; j * j <= i; ++j) {
20+
best = min(best, result[i - j * j] + 1);
21+
}
22+
result[i] = best;
23+
}
24+
return result[n];
25+
}
26+
};
27+
28+
int main() {
29+
30+
return 0;
31+
}
32+

0 commit comments

Comments
 (0)