1296. Divide Array in Sets of K Consecutive Numbers
https://leetcode.com/problems/divide-array-in-sets-of-k-consecutive-numbers/
Given an array of integers nums
and a positive integer k
, find whether it's possible to divide this array into sets of k
consecutive numbers
Return True
if its possible otherwise return False
.
Example 1:
Example 2:
Example 3:
Example 4:
Constraints:
1 <= nums.length <= 10^5
1 <= nums[i] <= 10^9
1 <= k <= nums.length
数组能否分成长度都为K的集合,每个集合内部满足差为1的等差序列。排好序后依次对每个元素找它后面K-1个是否存在,不存在说明不能分,存在就把它从数组中移除;继续遍历。
Last updated
Was this helpful?