当前位置:网站首页>1200. 最小绝对差
1200. 最小绝对差
2022-07-04 12:48:00 【anieoo】
原题链接:1200. 最小绝对差
solution:
排序+遍历
class Solution {
public:
vector<vector<int>> minimumAbsDifference(vector<int>& arr) {
vector<vector<int>> res; //定义返回值
sort(arr.begin(),arr.end());
int mindiff = INT_MAX;
for(int i = 1;i < arr.size();i++) {
if(arr[i] - arr[i - 1] < mindiff) {
res.clear();
res.push_back({arr[i - 1], arr[i]});
mindiff = arr[i] - arr[i - 1];
}
else if(arr[i] - arr[i - 1] == mindiff) {
res.push_back({arr[i - 1], arr[i]});
}
}
return res;
}
};
边栏推荐
- CVPR 2022 | 大幅减少零样本学习所需的人工标注,提出富含视觉信息的类别语义嵌入(源代码下载)...
- Install Trinity and solve error reporting
- Byte interview algorithm question
- Interviewer: what is the internal implementation of hash data type in redis?
- c#数组补充
- .NET 使用 redis
- XML入门一
- Automatic filling of database public fields
- 提高MySQL深分页查询效率的三种方案
- Fs4056 800mA charging IC domestic fast charging power IC
猜你喜欢
2022年山东省安全员C证考试题库及在线模拟考试
三星量产3纳米产品引台媒关注:能否短期提高投入产出率是与台积电竞争关键
OpenHarmony应用开发之如何创建DAYU200预览器
Three schemes to improve the efficiency of MySQL deep paging query
Interview disassembly: how to check the soaring usage of CPU after the system goes online?
Redis - how to install redis and configuration (how to quickly install redis on ubuntu18.04 and centos7.6 Linux systems)
2022年起重机械指挥考试模拟100题模拟考试平台操作
Flet tutorial 03 basic introduction to filledbutton (tutorial includes source code) (tutorial includes source code)
【R语言数据科学】:交叉验证再回首
Flet教程之 03 FilledButton基础入门(教程含源码)(教程含源码)
随机推荐
2022年起重机械指挥考试模拟100题模拟考试平台操作
Oracle 被 Ventana Research 评为数字创新奖总冠军
提高MySQL深分页查询效率的三种方案
ASP. Net core introduction I
The Secretary of Homeland Security warned immigrants "not to embark on a dangerous journey"
2022危险化学品经营单位主要负责人练习题及模拟考试
结合案例:Flink框架中的最底层API(ProcessFunction)用法
动画与过渡效果
Fs7867s is a voltage detection chip used for power supply voltage monitoring of digital system
C语言程序设计
易周金融 | Q1保险行业活跃人数8688.67万人 19家支付机构牌照被注销
Flet tutorial 03 basic introduction to filledbutton (tutorial includes source code) (tutorial includes source code)
Interviewer: what is the internal implementation of hash data type in redis?
SQL language
2022年山东省安全员C证考试题库及在线模拟考试
C#基础深入学习一
The only core indicator of high-quality software architecture
FS4056 800mA充电ic 国产快充电源ic
Byte interview algorithm question
面试拆解:系统上线后Cpu使用率飙升如何排查?