当前位置:网站首页>1200. Minimum absolute difference
1200. Minimum absolute difference
2022-07-04 14:00:00 【anieoo】
Original link :1200. Minimum absolute difference
solution:
Sort + Traverse
class Solution {
public:
vector<vector<int>> minimumAbsDifference(vector<int>& arr) {
vector<vector<int>> res; // Define the return value
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;
}
};边栏推荐
- 基于链表管理的单片机轮询程序框架
- Scrapy 框架学习
- Summary of recent days (non-technical article)
- Database lock table? Don't panic, this article teaches you how to solve it
- SQL语言
- Node の MongoDB安装
- 华昊中天冲刺科创板:年亏2.8亿拟募资15亿 贝达药业是股东
- Redis —— How To Install Redis And Configuration(如何快速在 Ubuntu18.04 与 CentOS7.6 Linux 系统上安装 Redis)
- ASP. Net core introduction I
- XML入门三
猜你喜欢

205. 同构字符串

Byte interview algorithm question

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

華昊中天沖刺科創板:年虧2.8億擬募資15億 貝達藥業是股東

安装trinity、解决报错

字节面试算法题

Redis - how to install redis and configuration (how to quickly install redis on ubuntu18.04 and centos7.6 Linux systems)

Personalized online cloud database hybrid optimization system | SIGMOD 2022 selected papers interpretation

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

博士申请 | 西湖大学学习与推理系统实验室招收博后/博士/研究实习等
随机推荐
Fs4056 800mA charging IC domestic fast charging power IC
Variable promotion and function promotion in JS
博士申请 | 西湖大学学习与推理系统实验室招收博后/博士/研究实习等
How to choose a technology stack for web applications in 2022
结合案例:Flink框架中的最底层API(ProcessFunction)用法
国内酒店交易DDD应用与实践——代码篇
以房抵债能否排除强制执行
安装trinity、解决报错
C foundation in-depth study I
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语言职工管理系统
C#基础补充
三星量产3纳米产品引台媒关注:能否短期提高投入产出率是与台积电竞争关键
动画与过渡效果
XML入门二
面试官:Redis中哈希数据类型的内部实现方式是什么?
学习项目是自己找的,成长机会是自己创造的
Oracle was named the champion of Digital Innovation Award by Ventana research
2022kdd pre lecture | 11 first-class scholars take you to unlock excellent papers in advance
. Net using redis