当前位置:网站首页>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;
}
};边栏推荐
- One of the solutions for unity not recognizing riders
- #yyds干货盘点# 解决名企真题:连续最大和
- 字节面试算法题
- PostgreSQL 9.1 soaring Road
- WPF double slider control and forced capture of mouse event focus
- Using nsproxy to forward messages
- 基于STM32+华为云IOT设计的酒驾监控系统
- Go zero micro service practical series (IX. ultimate optimization of seckill performance)
- 微服务入门
- JVM 内存布局详解,图文并茂,写得太好了!
猜你喜欢

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

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

Install Trinity and solve error reporting

HAProxy高可用解决方案

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

OPPO Find N2产品形态首曝:补齐各项短板

数据库公共字段自动填充

The only core indicator of high-quality software architecture

Dgraph: large scale dynamic graph dataset

Getting started with the go language is simple: go implements the Caesar password
随机推荐
2022年山东省安全员C证考试题库及在线模拟考试
Animation and transition effects
It is six orders of magnitude faster than the quantum chemical method. An adiabatic artificial neural network method based on adiabatic state can accelerate the simulation of dual nitrogen benzene der
Getting started with microservices
XML入门一
C语言程序设计选题参考
HAProxy高可用解决方案
基于STM32+华为云IOT设计的酒驾监控系统
Interviewer: what is the difference between redis expiration deletion strategy and memory obsolescence strategy?
Alibaba cloud award winning experience: build a highly available system with polardb-x
美国土安全部长:国内暴力极端主义是目前美面临的最大恐怖主义威胁之一
Install Trinity and solve error reporting
CA: efficient coordinate attention mechanism for mobile terminals | CVPR 2021
忠诚协议是否具有法律效力
Fs7867s is a voltage detection chip used for power supply voltage monitoring of digital system
C语言程序设计
Redis —— How To Install Redis And Configuration(如何快速在 Ubuntu18.04 与 CentOS7.6 Linux 系统上安装 Redis)
Don't turn down, three sentences to clarify the origin of cross domain resource request errors
2022g3 boiler water treatment examination question simulation examination question bank and simulation examination
Samsung's mass production of 3nm products has attracted the attention of Taiwan media: whether it can improve the input-output rate in the short term is the key to compete with TSMC