This commit is contained in:
2026-07-23 16:56:50 +08:00
parent 124ad9afdf
commit 92784ffb0f
36 changed files with 2015 additions and 608 deletions
+45
View File
@@ -0,0 +1,45 @@
package top100liked
import (
"testing"
)
// https://leetcode.cn/problems/perfect-squares/?envType=study-plan-v2&envId=top-100-liked
// 279. 完全平方数
//
// 给你一个整数 `n` ,返回 和为 `n` 的完全平方数的最少数量 。
// 完全平方数 是一个整数,其值等于另一个整数的平方;换句话说,其值等于一个整数自乘的积。例如,`1`、`4`、`9` 和 `16` 都是完全平方数,而 `3` 和 `11` 不是。
// 示例 1
// 输入:n = `12`
// 输出:3
// 解释:`12 = 4 + 4 + 4`
// 示例 2
// 输入:n = `13`
// 输出:2
// 解释:`13 = 4 + 9`
//
// 提示:
// - `1 <= n <= 10^4`
//
func numSquares(n int) int {
}
func TestNumSquares(t *testing.T) {
cases := []struct {
name string
n int
want int
}{
{"example1", 12, 3},
{"example2", 13, 2},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
got := numSquares(c.n)
if got != c.want {
t.Errorf("got %v, want %v", got, c.want)
}
})
}
}