当前位置:网站首页>6091. Divide the array so that the maximum difference is K
6091. Divide the array so that the maximum difference is K
2022-07-02 15:40:00 【Laver (nori)】
Ideas :
Prioritize , Then expand every possible interval , When the difference between the two ends of the interval exceeds Given range , Go directly to the next interval ;
class Solution {
public:
int partitionArray(vector<int>& nums, int k) {
int ans = 0;
// Sort the array first
sort(begin(nums), end(nums));
// The first element of the first subsequence
int start = nums[0];
// The default is a
ans = 1;
for(int i = 1; i < nums.size(); i++){
if(nums[i] - start <= k){
// If it is in the current sequence, skip
continue;
}
// Not in the current sequence , Then record the beginning element of a sequence
start = nums[i];
// Sequence number accumulation
ans++;
}
return ans;
}
};边栏推荐
猜你喜欢

SQL stored procedure

自定义异常

百变大7座,五菱佳辰产品力出众,人性化大空间,关键价格真香

损失函数与正负样本分配:YOLO系列

Leetcode skimming -- sum of two integers 371 medium

5. Practice: jctree implements the annotation processor at compile time

PTA 天梯赛习题集 L2-001 城市间紧急救援

2022 年辽宁省大学生数学建模A、B、C题(相关论文及模型程序代码网盘下载)

基于RZ/G2L | OK-G2LD-C开发板存储读写速度与网络实测

03.golang初步使用
随机推荐
02.面向容器化后,必须面对golang
(Video + graphic) machine learning introduction series - Chapter 5 machine learning practice
Bing.com網站
Beijing rental data analysis
LeetCode刷题——两整数之和#371#Medium
提前批院校名称
【LeetCode】1162-地图分析
Semantic segmentation learning notes (1)
[leetcode] 1140 stone game II
LeetCode_ String_ Simple_ 412.Fizz Buzz
6091. 划分数组使最大差为 K
[development environment] install the Chinese language pack for the 2013 version of visual studio community (install test agents 2013 | install visual studio 2013 simplified Chinese)
NBA player analysis
03. Preliminary use of golang
Leetcode question brushing - parity linked list 328 medium
Custom exception
How does the computer set up speakers to play microphone sound
Basic knowledge of cryptography
[leetcode] 1905 statistics sub Island
[leetcode] 977 square of ordered array