X Tutup
Skip to content

Commit 1857e2b

Browse files
author
liwentian
committed
Fd
1 parent 5d3d063 commit 1857e2b

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.leetcode.google;
2+
3+
/**
4+
* Created by liwentian on 2017/8/31.
5+
*/
6+
7+
public class PerfectSquares {
8+
9+
public int numSquares(int n) {
10+
int[] dp = new int[n + 1];
11+
12+
for (int i = 1; i <= n; i++) {
13+
int min = Integer.MAX_VALUE;
14+
for (int j = 1; i - j * j >= 0; j++) {
15+
min = Math.min(dp[i - j * j] + 1, min);
16+
}
17+
dp[i] = min;
18+
}
19+
20+
return dp[n];
21+
22+
}
23+
}

0 commit comments

Comments
 (0)
X Tutup