当前位置:网站首页>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;
}
};
边栏推荐
- Map of mL: Based on Boston house price regression prediction data set, an interpretable case is realized by using the map value to the LIR linear regression model
- C language book rental management system
- LVGL 8.2 keyboard
- Node mongodb installation
- 曝光一下阿里的工资待遇和职位级别
- Wt588f02b-8s (c006_03) single chip voice IC scheme enables smart doorbell design to reduce cost and increase efficiency
- Map of mL: Based on Boston house price regression prediction data set, an interpretable case of xgboost model using map value
- LVGL 8.2 Line
- Comment configurer un accord
- Why do domestic mobile phone users choose iPhone when changing a mobile phone?
猜你喜欢
An overview of 2D human posture estimation
各大主流编程语言性能PK,结果出乎意料
程序员自曝接私活:10个月时间接了30多个单子,纯收入40万
阿里被裁员工,找工作第N天,猎头又传来噩耗...
LVGL 8.2 Line wrap, recoloring and scrolling
Detailed explanation of visual studio debugging methods
Map of mL: Based on Boston house price regression prediction data set, an interpretable case of xgboost model using map value
LVGL 8.2 Line
金额计算用 BigDecimal 就万无一失了?看看这五个坑吧~~
Digi重启XBee-Pro S2C生产,有些差别需要注意
随机推荐
深度学习7 Transformer系列实例分割Mask2Former
Transplant tinyplay for imx6q development board QT system
Compile oglpg-9th-edition source code with clion
局部修改-渐进型开发
【C语言】指针笔试题
Expose Ali's salary and position level
内存管理总结
Detailed analysis of pytorch's automatic derivation mechanism, pytorch's core magic
C language personal address book management system
Combined with case: the usage of the lowest API (processfunction) in Flink framework
如何配和弦
Nowcoder reverse linked list
Digi XBee 3 rf: 4 protocols, 3 packages, 10 major functions
Digi restarts XBee Pro S2C production. Some differences need to be noted
Ultrasonic distance meter based on 51 single chip microcomputer
Leetcode t49: grouping of alphabetic words
Docker compose public network deployment redis sentinel mode
LeetCode 1200 最小绝对差[排序] HERODING的LeetCode之路
Practical puzzle solving | how to extract irregular ROI regions in opencv
Scratch Castle Adventure Electronic Society graphical programming scratch grade examination level 3 true questions and answers analysis June 2022