当前位置:网站首页>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;
}
};
边栏推荐
- [cloud native] how can I compete with this database?
- AI and Life Sciences
- Detailed explanation of visual studio debugging methods
- Visual Studio调试方式详解
- LVLG 8.2 circular scrolling animation of a label
- LVGL 8.2 text shadow
- 阿里被裁员工,找工作第N天,猎头又传来噩耗...
- 毕业季-个人总结
- LVGL 8.2 Line wrap, recoloring and scrolling
- C language book rental management system
猜你喜欢
Digi XBee 3 RF: 4个协议,3种封装,10个大功能
flink sql-client. SH tutorial
LVGL 8.2 Draw label with gradient color
Programmers exposed that they took private jobs: they took more than 30 orders in 10 months, with a net income of 400000
Practical puzzle solving | how to extract irregular ROI regions in opencv
[information retrieval] experiment of classification and clustering
Docker compose public network deployment redis sentinel mode
Detailed explanation of visual studio debugging methods
leetcode:6109. Number of people who know the secret [definition of DP]
scratch古堡历险记 电子学会图形化编程scratch等级考试三级真题和答案解析2022年6月
随机推荐
A collection of classic papers on convolutional neural networks (deep learning classification)
Leetcode T48: rotating images
Codeforce:c. sum of substrings
自动控制原理快速入门+理解
阿里被裁员工,找工作第N天,猎头又传来噩耗...
LVGL 8.2 List
leetcode:6110. The number of incremental paths in the grid graph [DFS + cache]
Leetcode t47: full arrangement II
炒股网上开户安全吗?会不会被骗。
LVGL 8.2 text shadow
Free, easy-to-use, powerful lightweight note taking software evaluation: drafts, apple memo, flomo, keep, flowus, agenda, sidenote, workflow
Ml: introduction, principle, use method and detailed introduction of classic cases of snap value
函数计算异步任务能力介绍 - 任务触发去重
leetcode:6109. Number of people who know the secret [definition of DP]
各大主流编程语言性能PK,结果出乎意料
Scratch Castle Adventure Electronic Society graphical programming scratch grade examination level 3 true questions and answers analysis June 2022
Is it safe to open an account online for stock speculation? Will you be cheated.
[algorithm leetcode] interview question 04.03 Specific depth node linked list (Multilingual Implementation)
关于FPGA底层资源的细节问题
LVGL 8.2 LED