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/partition-equal-subset-sum/?envType=study-plan-v2&envId=top-100-liked
// 416. 分割等和子集
//
// 给你一个 只包含正整数 的 非空 数组 `nums` 。请你判断是否可以将这个数组分割成两个子集,使得两个子集的元素和相等。
// 示例 1
// 输入:nums = [1,5,11,5]
// 输出:true
// 解释:数组可以分割成 [1, 5, 5] 和 [11] 。
// 示例 2
// 输入:nums = [1,2,3,5]
// 输出:false
// 解释:数组不能分割成两个元素和相等的子集。
//
// 提示:
// - `1 <= nums.length <= 200`
// - `1 <= nums[i] <= 100`
//
func canPartition(nums []int) bool {
}
func TestCanPartition(t *testing.T) {
cases := []struct {
name string
nums []int
want bool
}{
{"example1", []int{1, 5, 11, 5}, true},
{"example2", []int{1, 2, 3, 5}, false},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
got := canPartition(c.nums)
if got != c.want {
t.Errorf("got %v, want %v", got, c.want)
}
})
}
}