当前位置:网站首页>Leetcode 1200 minimum absolute difference [sort] The Path of leetcode for heroding
Leetcode 1200 minimum absolute difference [sort] The Path of leetcode for heroding
2022-07-04 14:45:00 【Heroding23】

Comment résoudre le problème:
Trier d'abord,Comme la différence absolue minimale doit être entre les chiffres adjacents,Donc les deux traversées sont comparées,Réglez undiffDifférence comme différence minimale,Mettre à jour si vous rencontrez plus petit,Et viderans,Les codes sont les suivants::
class Solution {
public:
vector<vector<int>> minimumAbsDifference(vector<int>& arr) {
int n = arr.size();
sort(arr.begin(), arr.end());
int diff = arr[1] - arr[0];
vector<vector<int>> ans;
for(int i = 1; i < n; i ++) {
if(arr[i] - arr[i - 1] == diff) {
ans.push_back({
arr[i - 1], arr[i]});
} else if(arr[i] - arr[i - 1] < diff) {
diff = arr[i] - arr[i - 1];
ans.clear();
ans.push_back({
arr[i - 1], arr[i]});
} else continue;
}
return ans;
}
};
边栏推荐
- leetcode:6109. Number of people who know the secret [definition of DP]
- 《opencv学习笔记》-- 线性滤波:方框滤波、均值滤波、高斯滤波
- LVGL 8.2 Line wrap, recoloring and scrolling
- Popular framework: the use of glide
- Alcohol driving monitoring system based on stm32+ Huawei cloud IOT design
- C language course design questions
- 关于miui12.5 红米k20pro用au或者povo2出现问题的解决办法
- EventBridge 在 SaaS 企业集成领域的探索与实践
- ES6 modularization
- Leetcode t49: grouping of alphabetic words
猜你喜欢

Chapter 17 process memory

Nowcoder reverse linked list

Detailed analysis of pytorch's automatic derivation mechanism, pytorch's core magic

Digi XBee 3 RF: 4个协议,3种封装,10个大功能

自动控制原理快速入门+理解

软件测试之测试评估

Talk about 10 tips to ensure thread safety
![[information retrieval] link analysis](/img/dc/4956e8e21d8ce6be1db1822d19ca61.png)
[information retrieval] link analysis

Test evaluation of software testing

leetcode:6110. 网格图中递增路径的数目【dfs + cache】
随机推荐
Test evaluation of software testing
Practical puzzle solving | how to extract irregular ROI regions in opencv
LVGL 8.2 List
One architecture to complete all tasks - transformer architecture is unifying the AI Jianghu on its own
LeetCode 1200 最小绝对差[排序] HERODING的LeetCode之路
Graduation season - personal summary
Count the running time of PHP program and set the maximum running time of PHP
LVGL 8.2 Menu
Combined with case: the usage of the lowest API (processfunction) in Flink framework
LVGL 8.2 List
leetcode:6110. 网格图中递增路径的数目【dfs + cache】
How to match chords
Solutions to the problems of miui12.5 red rice k20pro using Au or povo2
Leetcode 61: rotating linked list
C language personal address book management system
C language book rental management system
各大主流编程语言性能PK,结果出乎意料
C language programming
PyTorch的自动求导机制详细解析,PyTorch的核心魔法
(1) The standard of performance tuning and the correct posture for tuning - if you have performance problems, go to the heapdump performance community!