当前位置:网站首页>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;
}
};边栏推荐
猜你喜欢

2022危险化学品经营单位主要负责人练习题及模拟考试

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

Detailed explanation of Fisher information quantity detection countermeasure sample code

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

Interview disassembly: how to check the soaring usage of CPU after the system goes online?

基于链表管理的单片机轮询程序框架

光环效应——谁说头上有光的就算英雄

8 expansion sub packages! Recbole launches 2.0!

Dgraph: large scale dynamic graph dataset

Go 语言入门很简单:Go 实现凯撒密码
随机推荐
AI painting minimalist tutorial
免费、好用、强大的轻量级笔记软件评测:Drafts、Apple 备忘录、Flomo、Keep、FlowUs、Agenda、SideNote、Workflowy
OPPO Find N2产品形态首曝:补齐各项短板
C foundation in-depth learning II
Introduction to reverse debugging PE structure resource table 07/07
C#基础补充
C array supplement
源码编译安装MySQL
C语言宿舍管理查询软件
ASP. Net core introduction I
一次 Keepalived 高可用的事故,让我重学了一遍它
Read the BGP agreement in 6 minutes.
基于链表管理的单片机轮询程序框架
XML入门三
Byte interview algorithm question
.NET 使用 redis
Web knowledge supplement
Oracle 被 Ventana Research 评为数字创新奖总冠军
Redis - how to install redis and configuration (how to quickly install redis on ubuntu18.04 and centos7.6 Linux systems)
Install Trinity and solve error reporting