当前位置:网站首页>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;
}
};边栏推荐
- 面试拆解:系统上线后Cpu使用率飙升如何排查?
- 以房抵债能否排除强制执行
- Redis - how to install redis and configuration (how to quickly install redis on ubuntu18.04 and centos7.6 Linux systems)
- 美国土安全部长:国内暴力极端主义是目前美面临的最大恐怖主义威胁之一
- Fs4056 800mA charging IC domestic fast charging power IC
- Install Trinity and solve error reporting
- ViewBinding和DataBinding的理解和区别
- Oracle was named the champion of Digital Innovation Award by Ventana research
- Scripy framework learning
- C language dormitory management query software
猜你喜欢

高质量软件架构的唯一核心指标

Introduction to reverse debugging PE structure resource table 07/07

8 expansion sub packages! Recbole launches 2.0!

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

Doctoral application | West Lake University Learning and reasoning system laboratory recruits postdoctoral / doctoral / research internship, etc

ViewBinding和DataBinding的理解和区别

2022kdd pre lecture | 11 first-class scholars take you to unlock excellent papers in advance

【Antd】Antd 如何在 Form.Item 中有 Input.Gourp 时获取 Input.Gourp 的每一个 Input 的value
提高MySQL深分页查询效率的三种方案
![30: Chapter 3: develop Passport Service: 13: develop [change / improve user information, interface]; (use * * * Bo class to accept parameters, and use parameter verification)](/img/89/aabf79ca02bf587e93885cadd5f98a.png)
30: Chapter 3: develop Passport Service: 13: develop [change / improve user information, interface]; (use * * * Bo class to accept parameters, and use parameter verification)
随机推荐
Web知识补充
. Net using redis
Flet教程之 03 FilledButton基础入门(教程含源码)(教程含源码)
C語言宿舍管理查詢軟件
C language staff management system
C语言图书租赁管理系统
2022年山东省安全员C证考试题库及在线模拟考试
微服务入门
嵌入式编程中五个必探的“潜在错误”
unity不识别rider的其中一种解决方法
Alibaba cloud award winning experience: build a highly available system with polardb-x
The old-fashioned synchronized lock optimization will make it clear to you at once!
[FAQ] summary of common causes and solutions of Huawei account service error 907135701
. Net delay queue
.Net之延迟队列
[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
XML入门二
易周金融 | Q1保险行业活跃人数8688.67万人 19家支付机构牌照被注销
提高MySQL深分页查询效率的三种方案
【Antd踩坑】Antd Form 配合Input.Group时出现Form.Item所占据的高度不对