当前位置:网站首页>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;
}
};边栏推荐
- Animation and transition effects
- Introduction to reverse debugging PE structure resource table 07/07
- 美国土安全部部长警告移民“不要踏上危险的旅程”
- 源码编译安装MySQL
- CVPR 2022 | 大幅减少零样本学习所需的人工标注,提出富含视觉信息的类别语义嵌入(源代码下载)...
- 2022年起重机械指挥考试模拟100题模拟考试平台操作
- remount of the / superblock failed: Permission denied
- .Net之延迟队列
- C basic supplement
- 提高MySQL深分页查询效率的三种方案
猜你喜欢

2022年山东省安全员C证考试题库及在线模拟考试

Flet教程之 03 FilledButton基础入门(教程含源码)(教程含源码)

【Antd】Antd 如何在 Form.Item 中有 Input.Gourp 时获取 Input.Gourp 的每一个 Input 的value

ASP. Net core introduction I

CTF competition problem solution STM32 reverse introduction

MySQL45讲——学习极客时间MySQL实战45讲笔记—— 06 | 全局锁和表锁_给表加个字段怎么有这么多阻碍

一次 Keepalived 高可用的事故,让我重学了一遍它

30:第三章:开发通行证服务:13:开发【更改/完善用户信息,接口】;(使用***BO类承接参数,并使用了参数校验)

Redis —— How To Install Redis And Configuration(如何快速在 Ubuntu18.04 与 CentOS7.6 Linux 系统上安装 Redis)

MySQL 45 lecture - learn the actual combat notes of MySQL in Geek time 45 lecture - 06 | global lock and table lock_ Why are there so many obstacles in adding a field to the table
随机推荐
美国土安全部部长警告移民“不要踏上危险的旅程”
C語言宿舍管理查詢軟件
Go zero micro service practical series (IX. ultimate optimization of seckill performance)
Dgraph: large scale dynamic graph dataset
【Antd踩坑】Antd Form 配合Input.Group时出现Form.Item所占据的高度不对
C language programming topic reference
XML入门二
SCM polling program framework based on linked list management
CTF competition problem solution STM32 reverse introduction
. Net delay queue
30: Chapter 3: develop Passport Service: 13: develop [change / improve user information, interface]; (use * * * Bo class to accept parameters, and use parameter verification)
程序员转方向
Service Mesh的基本模式
Node の MongoDB 安装
The only core indicator of high-quality software architecture
Redis - how to install redis and configuration (how to quickly install redis on ubuntu18.04 and centos7.6 Linux systems)
[FAQ] summary of common causes and solutions of Huawei account service error 907135701
好博医疗冲刺科创板:年营收2.6亿 万永钢和沈智群为实控人
提高MySQL深分页查询效率的三种方案
Detailed explanation of Fisher information quantity detection countermeasure sample code