Files
leetcode/top-100-liked/84/leetcode_test.go
T
2026-07-23 16:56:50 +08:00

46 lines
1006 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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)
}
})
}
}