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

46 lines
1.0 KiB
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/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)
}
})
}
}