当前位置:网站首页>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;
}
};
边栏推荐
- C語言宿舍管理查詢軟件
- 好博医疗冲刺科创板:年营收2.6亿 万永钢和沈智群为实控人
- CA: efficient coordinate attention mechanism for mobile terminals | CVPR 2021
- C#基础补充
- E-week finance | Q1 the number of active people in the insurance industry was 86.8867 million, and the licenses of 19 Payment institutions were cancelled
- 2022kdd pre lecture | 11 first-class scholars take you to unlock excellent papers in advance
- C foundation in-depth learning II
- C语言个人通讯录管理系统
- Optional values and functions of the itemized contenttype parameter in the request header
- C语言宿舍管理查询软件
猜你喜欢
Dgraph: large scale dynamic graph dataset
上汽大通MAXUS正式发布全新品牌“MIFA”,旗舰产品MIFA 9正式亮相!
光环效应——谁说头上有光的就算英雄
Summary of recent days (non-technical article)
2022KDD预讲 | 11位一作学者带你提前解锁优秀论文
2022年山东省安全员C证考试题库及在线模拟考试
Fisher信息量检测对抗样本代码详解
30:第三章:开发通行证服务:13:开发【更改/完善用户信息,接口】;(使用***BO类承接参数,并使用了参数校验)
2022年起重机械指挥考试模拟100题模拟考试平台操作
One of the solutions for unity not recognizing riders
随机推荐
2022 hoisting machinery command examination simulation 100 questions simulation examination platform operation
Using scrcpy projection
Lick the dog until the last one has nothing (state machine)
2022G3锅炉水处理考试题模拟考试题库及模拟考试
Redis —— How To Install Redis And Configuration(如何快速在 Ubuntu18.04 与 CentOS7.6 Linux 系统上安装 Redis)
Doctoral application | West Lake University Learning and reasoning system laboratory recruits postdoctoral / doctoral / research internship, etc
C语言职工管理系统
Source code compilation and installation of MySQL
remount of the / superblock failed: Permission denied
Flet教程之 03 FilledButton基础入门(教程含源码)(教程含源码)
程序员转方向
C basic supplement
CANN算子:利用迭代器高效实现Tensor数据切割分块处理
硬件基础知识-二极管基础
Fs4056 800mA charging IC domestic fast charging power IC
[FAQ] summary of common causes and solutions of Huawei account service error 907135701
Alibaba cloud award winning experience: build a highly available system with polardb-x
XML入门一
美国土安全部部长警告移民“不要踏上危险的旅程”
Node mongodb installation