当前位置:网站首页>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;
}
};边栏推荐
- [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)
- 2278. 字母在字符串中的百分比
- [network security] network asset collection
- 02. After containerization, you must face golang
- (Video + graphic) machine learning introduction series - Chapter 5 machine learning practice
- Wechat Alipay account system and payment interface business process
- Basic knowledge of cryptography
- 13_ Redis_ affair
- 2022 college students in Liaoning Province mathematical modeling a, B, C questions (related papers and model program code online disk download)
- Be a good gatekeeper on the road of anti epidemic -- infrared thermal imaging temperature detection system based on rk3568
猜你喜欢

YOLOV5 代码复现以及搭载服务器运行

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

15_ Redis_ Redis. Conf detailed explanation

Be a good gatekeeper on the road of anti epidemic -- infrared thermal imaging temperature detection system based on rk3568

【网络安全】网络资产收集

Bing. Com website

Redux - detailed explanation

How to avoid 7 common problems in mobile and network availability testing

Leetcode skimming -- sum of two integers 371 medium

微信支付宝账户体系和支付接口业务流程
随机推荐
Leetcode question brushing - parity linked list 328 medium
Leetcode skimming -- verifying the preorder serialization of binary tree # 331 # medium
02.面向容器化后,必须面对golang
Thoroughly understand browser strong cache and negotiation cache
MySQL -- Index Optimization -- order by
PTA ladder game exercise set l2-001 inter city emergency rescue
[leetcode] 344 reverse string
MD5加密
List of sergeant schools
【LeetCode】19-删除链表的倒数第N个结点
损失函数与正负样本分配:YOLO系列
College entrance examination score line climbing
18_ Redis_ Redis master-slave replication & cluster building
LeetCode刷题——统计各位数字都不同的数字个数#357#Medium
6.12 critical moment of Unified Process Platform
【Salesforce】如何确认你的Salesforce版本?
. Net again! Happy 20th birthday
Engineer evaluation | rk3568 development board hands-on test
【LeetCode】1254-统计封闭岛屿的数量
10_Redis_geospatial_命令