当前位置:网站首页>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;
}
};
边栏推荐
- flink sql-client. SH tutorial
- Visual Studio调试方式详解
- PyTorch的自动求导机制详细解析,PyTorch的核心魔法
- Red envelope activity design in e-commerce system
- Ali was laid off employees, looking for a job n day, headhunters came bad news
- Combined with case: the usage of the lowest API (processfunction) in Flink framework
- Abnormal value detection using shap value
- ES6 modularization
- Digi XBee 3 rf: 4 protocols, 3 packages, 10 major functions
- 自动控制原理快速入门+理解
猜你喜欢
Explain of SQL optimization
如何配和弦
实战解惑 | OpenCV中如何提取不规则ROI区域
Transplant tinyplay for imx6q development board QT system
An overview of 2D human posture estimation
[information retrieval] experiment of classification and clustering
为什么国产手机用户换下一部手机时,都选择了iPhone?
5g TV cannot become a competitive advantage, and video resources become the last weapon of China's Radio and television
【MySQL从入门到精通】【高级篇】(四)MySQL权限管理与控制
Docker compose public network deployment redis sentinel mode
随机推荐
Digi重启XBee-Pro S2C生产,有些差别需要注意
Sqlserver functions, creation and use of stored procedures
炒股网上开户安全吗?会不会被骗。
(1)性能调优的标准和做好调优的正确姿势-有性能问题,上HeapDump性能社区!
Gin integrated Alipay payment
scratch古堡历险记 电子学会图形化编程scratch等级考试三级真题和答案解析2022年6月
潘多拉 IOT 开发板学习(RT-Thread)—— 实验3 按键实验(学习笔记)
Comment configurer un accord
Programmers exposed that they took private jobs: they took more than 30 orders in 10 months, with a net income of 400000
flink sql-client. SH tutorial
曝光一下阿里的工资待遇和职位级别
Progress in architecture
毕业季-个人总结
Kubernets Pod 存在 Finalizers 一直处于 Terminating 状态
An overview of 2D human posture estimation
LVGL 8.2 Draw label with gradient color
openresty 重定向
C language personal address book management system
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
(1) The standard of performance tuning and the correct posture for tuning - if you have performance problems, go to the heapdump performance community!