当前位置:网站首页>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;
}
};
边栏推荐
- Scratch Castle Adventure Electronic Society graphical programming scratch grade examination level 3 true questions and answers analysis June 2022
- ML:SHAP值的简介、原理、使用方法、经典案例之详细攻略
- C language small commodity management system
- LVGL 8.2 Draw label with gradient color
- 【C语言】指针笔试题
- Query optimizer for SQL optimization
- Respect others' behavior
- Node mongodb installation
- [C language] Pointer written test questions
- ML之shap:基于boston波士顿房价回归预测数据集利用shap值对XGBoost模型实现可解释性案例
猜你喜欢

What is the difference between Bi financial analysis in a narrow sense and financial analysis in a broad sense?

Leetcode 61: rotating linked list

Nowcoder reverse linked list

金额计算用 BigDecimal 就万无一失了?看看这五个坑吧~~

5g TV cannot become a competitive advantage, and video resources become the last weapon of China's Radio and television

Gin integrated Alipay payment

Combined with case: the usage of the lowest API (processfunction) in Flink framework

Compile oglpg-9th-edition source code with clion

LVGL 8.2 LED

scratch古堡历险记 电子学会图形化编程scratch等级考试三级真题和答案解析2022年6月
随机推荐
深度学习7 Transformer系列实例分割Mask2Former
The failure rate is as high as 80%. What are the challenges on the way of enterprise digital transformation?
Pandora IOT development board learning (RT thread) - Experiment 3 button experiment (learning notes)
Summary of common problems in development
LVGL 8.2 LED
Opencv3.2 and opencv2.4 installation
Deep learning 7 transformer series instance segmentation mask2former
LVGL 8.2 Line
ML之shap:基于boston波士顿房价回归预测数据集利用Shap值对LiR线性回归模型实现可解释性案例
Opencv learning notes - linear filtering: box filtering, mean filtering, Gaussian filtering
LVGL 8.2 Menu
Comment configurer un accord
实战解惑 | OpenCV中如何提取不规则ROI区域
C language course design questions
openresty 限流
Solutions aux problèmes d'utilisation de l'au ou du povo 2 dans le riz rouge k20pro MIUI 12.5
LVGL 8.2 LED
A keepalived high availability accident made me learn it again
leecode学习笔记-约瑟夫问题
Solutions to the problems of miui12.5 red rice k20pro using Au or povo2