当前位置:网站首页>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;
}
};
边栏推荐
- Query optimizer for SQL optimization
- [MySQL from introduction to proficiency] [advanced chapter] (V) SQL statement execution process of MySQL
- leetcode:6110. 网格图中递增路径的数目【dfs + cache】
- Practical puzzle solving | how to extract irregular ROI regions in opencv
- Why do domestic mobile phone users choose iPhone when changing a mobile phone?
- AI与生命科学
- C language set operation
- [cloud native] how can I compete with this database?
- Compile oglpg-9th-edition source code with clion
- Red envelope activity design in e-commerce system
猜你喜欢
Digi restarts XBee Pro S2C production. Some differences need to be noted
Kubernets Pod 存在 Finalizers 一直处于 Terminating 状态
(1)性能调优的标准和做好调优的正确姿势-有性能问题,上HeapDump性能社区!
潘多拉 IOT 开发板学习(RT-Thread)—— 实验3 按键实验(学习笔记)
金额计算用 BigDecimal 就万无一失了?看看这五个坑吧~~
Opencv learning notes - linear filtering: box filtering, mean filtering, Gaussian filtering
[information retrieval] link analysis
现代控制理论入门+理解
Xcode abnormal pictures cause IPA packet size problems
Ali was laid off employees, looking for a job n day, headhunters came bad news
随机推荐
LVGL 8.2 Menu
92. (cesium chapter) cesium building layering
Xcode abnormal pictures cause IPA packet size problems
LVGL 8.2 Line
scratch古堡历险记 电子学会图形化编程scratch等级考试三级真题和答案解析2022年6月
[information retrieval] experiment of classification and clustering
C language book rental management system
各大主流编程语言性能PK,结果出乎意料
Explain of SQL optimization
自动控制原理快速入门+理解
金额计算用 BigDecimal 就万无一失了?看看这五个坑吧~~
ML之shap:基于boston波士顿房价回归预测数据集利用shap值对XGBoost模型实现可解释性案例
openresty 限流
Leetcode t49: grouping of alphabetic words
Intelligence d'affaires bi analyse financière, analyse financière au sens étroit et analyse financière au sens large sont - ils différents?
Detailed analysis of pytorch's automatic derivation mechanism, pytorch's core magic
Opencv3.2 and opencv2.4 installation
LVGL 8.2 keyboard
Ml: introduction, principle, use method and detailed introduction of classic cases of snap value
架构方面的进步