当前位置:网站首页>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;
}
};
边栏推荐
- 如何配和弦
- Pandora IOT development board learning (RT thread) - Experiment 3 button experiment (learning notes)
- Detailed explanation of visual studio debugging methods
- C language programming
- LVGL 8.2 Sorting a List using up and down buttons
- 深度学习7 Transformer系列实例分割Mask2Former
- LVGL 8.2 text shadow
- 金额计算用 BigDecimal 就万无一失了?看看这五个坑吧~~
- 产业互联网则具备更大的发展潜能,具备更多的行业场景
- Xcode abnormal pictures cause IPA packet size problems
猜你喜欢
![[C language] Pointer written test questions](/img/89/3d463cbbb321e45ba8342f0ddfef8f.png)
[C language] Pointer written test questions

Chapter 17 process memory

Digi重启XBee-Pro S2C生产,有些差别需要注意

如何配和弦

How to match chords

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

Talk about 10 tips to ensure thread safety

UFO:微软学者提出视觉语言表征学习的统一Transformer,在多个多模态任务上达到SOTA性能!...

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

金额计算用 BigDecimal 就万无一失了?看看这五个坑吧~~
随机推荐
LVGL 8.2 Draw label with gradient color
Intelligence d'affaires bi analyse financière, analyse financière au sens étroit et analyse financière au sens large sont - ils différents?
如何配和弦
Respect others' behavior
Wt588f02b-8s (c006_03) single chip voice IC scheme enables smart doorbell design to reduce cost and increase efficiency
LVGL 8.2 Line wrap, recoloring and scrolling
Opencv learning notes - linear filtering: box filtering, mean filtering, Gaussian filtering
Practical puzzle solving | how to extract irregular ROI regions in opencv
内存管理总结
EventBridge 在 SaaS 企业集成领域的探索与实践
【MySQL从入门到精通】【高级篇】(五)MySQL的SQL语句执行流程
Compile oglpg-9th-edition source code with clion
10. (map data) offline terrain data processing (for cesium)
为什么国产手机用户换下一部手机时,都选择了iPhone?
Kubernets Pod 存在 Finalizers 一直处于 Terminating 状态
Real time data warehouse
C language achievement management system for middle school students
产业互联网则具备更大的发展潜能,具备更多的行业场景
Leetcode 61: rotating linked list
Pandora IOT development board learning (RT thread) - Experiment 3 button experiment (learning notes)