We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5d3d063 commit 1857e2bCopy full SHA for 1857e2b
google/src/main/java/com/leetcode/google/PerfectSquares.java
@@ -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