当前位置:网站首页>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;
}
};边栏推荐
- Cann operator: using iterators to efficiently realize tensor data cutting and blocking processing
- .NET 使用 redis
- Service Mesh的基本模式
- C语言宿舍管理查询软件
- 逆向调试入门-PE结构-资源表07/07
- Personalized online cloud database hybrid optimization system | SIGMOD 2022 selected papers interpretation
- [AI system frontier dynamics, issue 40] Hinton: my deep learning career and research mind method; Google refutes rumors and gives up tensorflow; The apotheosis framework is officially open source
- Runc hang causes the kubernetes node notready
- JVM 内存布局详解,图文并茂,写得太好了!
- Commvault 和 Oracle 合作,在 Oracle 云上提供 Metallic数据管理即服务
猜你喜欢

Getting started with the go language is simple: go implements the Caesar password

2022 hoisting machinery command examination simulation 100 questions simulation examination platform operation

Fisher信息量检测对抗样本代码详解
Three schemes to improve the efficiency of MySQL deep paging query

7 月数据库排行榜:MongoDB 和 Oracle 分数下降最多

Five "potential errors" in embedded programming

Interviewer: what is the internal implementation of hash data type in redis?

免费、好用、强大的轻量级笔记软件评测:Drafts、Apple 备忘录、Flomo、Keep、FlowUs、Agenda、SideNote、Workflowy

Oracle was named the champion of Digital Innovation Award by Ventana research

2022KDD预讲 | 11位一作学者带你提前解锁优秀论文
随机推荐
.NET 使用 redis
C basic supplement
How to choose a technology stack for web applications in 2022
CTF competition problem solution STM32 reverse introduction
After the game starts, you will be prompted to install HMS core. Click Cancel, and you will not be prompted to install HMS core again (initialization failure returns 907135003)
Scrapy 框架学习
Understanding and difference between viewbinding and databinding
Node mongodb installation
好博医疗冲刺科创板:年营收2.6亿 万永钢和沈智群为实控人
Worried about "cutting off gas", Germany is revising the energy security law
Three schemes to improve the efficiency of MySQL deep paging query
Byte interview algorithm question
C語言宿舍管理查詢軟件
Using scrcpy projection
js中的变量提升和函数提升
舔狗舔到最后一无所有(状态机)
Cors: standard scheme of cross domain resource request
C语言个人通讯录管理系统
JVM系列——栈与堆、方法区day1-2
面试官:Redis中哈希数据类型的内部实现方式是什么?