###### 279. Perfect Squares

Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n.

Example 1:

Input: n = 12
Output: 3
Explanation: 12 = 4 + 4 + 4.

Example 2:

Input: n = 13
Output: 2
Explanation: 13 = 4 + 9.

class Solution {
public:
int numSquares(int n) {
vector<int> minS(n+1, INT_MAX);
minS[0] = 0;
for(int i = 1; i <= n; i++){
for(int j = 1; j*j <= i; j++){
minS[i] = min(minS[i], minS[i-j*j] + 1);
}
}
return minS[n];
}
};

#### LeetCode--279. Perfect Squares（完美平方）Python

2018-01-02 17:01:12

#### LeetCode（279）Perfect Squares

2015-11-29 14:50:57

#### leetcode 279: Perfect Squares

2015-09-10 06:03:01

#### LeetCode解题报告 279. Perfect Squares [medium]

2016-12-17 00:52:52

#### [leetcode-279]Perfect Squares(java)

2015-09-25 08:16:39

#### 279 Perfect Squares

2015-09-10 10:11:15

#### [LeetCode 279] Perfect Squares

2015-09-18 13:11:08

#### LeetCode 279. Perfect Squares（完美平方）

2016-04-14 04:51:40

#### LeetCode-279. Perfect Squares | (JAVA) (完美平方数)

2017-04-13 19:14:08

#### Leetcode-279_Perfect Squares（完美广场）-动态规划、数学、广度优先遍历-【C++】

2018-02-09 11:51:44

## 不良信息举报

279. Perfect Squares