Skip to content

Latest commit

 

History

History
64 lines (45 loc) · 1.87 KB

0698-partition-to-k-equal-sum-subsets.adoc

File metadata and controls

64 lines (45 loc) · 1.87 KB

698. Partition to K Equal Sum Subsets

{leetcode}/problems/partition-to-k-equal-sum-subsets/[LeetCode - 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:

Input: nums = [4, 3, 2, 3, 5, 2, 1], k = 4
Output: True
Explanation: It's possible to divide it into 4 subsets (5), (1, 4), (2,3), (2,3) with equal sums.

Note:

  • 1 ⇐ k ⇐ len(nums) ⇐ 16.

  • 0 < nums[i] < 10000.

思路分析

球视角

{image_attr}
一刷(超时)
link:{sourcedir}/_0698_PartitionToKEqualSumSubsets.java[role=include]
一刷(优化)
link:{sourcedir}/_0698_PartitionToKEqualSumSubsets_1.java[role=include]

桶视角

回头尝试一下桶视角的解法。

{image_attr}