698. Partition to K Equal Sum Subsets
题目描述
Given an array of integers nums and a positive integer k, find whether it’s possible to divide this array into k non-empty subsets whose sums are all equal.
Example 1:123Input: nums = [4, 3, 2, 3, 5, 2, 1], k = 4Output: TrueExplanation: It's possible to divide it into 4 subsets (5), (1, 4), (2,3), (2,3) with equal sums.
题目大意
将数组平均分成 k
个子序列,每个子序列和相同。
解题思路
递归遍历数组,用
visited
标记访问过的元素。
代码
|
|