279. Perfect Squares Medium

@problem@discussion
#Math#Dynamic Programming#Breadth-First Search



1/**
2 * [279] Perfect Squares
3 *
4 * Given an integer n, return the least number of perfect square numbers that sum to n.
5 * A perfect square is an integer that is the square of an integer; in other words, it is the product of some integer with itself. For example, 1, 4, 9, and 16 are perfect squares while 3 and 11 are not.
6 *  
7 * Example 1:
8 * 
9 * Input: n = 12
10 * Output: 3
11 * Explanation: 12 = 4 + 4 + 4.
12 * 
13 * Example 2:
14 * 
15 * Input: n = 13
16 * Output: 2
17 * Explanation: 13 = 4 + 9.
18 * 
19 *  
20 * Constraints:
21 * 
22 * 	1 <= n <= 10^4
23 * 
24 */
25pub struct Solution {}
26
27// problem: https://leetcode.com/problems/perfect-squares/
28// discuss: https://leetcode.com/problems/perfect-squares/discuss/?currentPage=1&orderBy=most_votes&query=
29
30// submission codes start here
31
32impl Solution {
33    pub fn num_squares(n: i32) -> i32 {
34        0
35    }
36}
37
38// submission codes end
39
40#[cfg(test)]
41mod tests {
42    use super::*;
43
44    #[test]
45    fn test_279() {
46    }
47}
48


Back
© 2025 bowen.ge All Rights Reserved.