当前位置:网站首页>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;
}
};
边栏推荐
- 各大主流编程语言性能PK,结果出乎意料
- [information retrieval] experiment of classification and clustering
- A collection of classic papers on convolutional neural networks (deep learning classification)
- Opencv3.2 and opencv2.4 installation
- Progress in architecture
- Comment configurer un accord
- AI与生命科学
- First experience of ViewModel
- 关于miui12.5 红米k20pro用au或者povo2出现问题的解决办法
- LVGL 8.2 Menu
猜你喜欢

Ranking list of databases in July: mongodb and Oracle scores fell the most

Xcode abnormal pictures cause IPA packet size problems
![[information retrieval] experiment of classification and clustering](/img/05/ee3b3bc4ab79d52b63cdc34305aa57.png)
[information retrieval] experiment of classification and clustering

Expose Ali's salary and position level

关于FPGA底层资源的细节问题

An overview of 2D human posture estimation

Ali was laid off employees, looking for a job n day, headhunters came bad news

实战解惑 | OpenCV中如何提取不规则ROI区域

如何配和弦

92. (cesium chapter) cesium building layering
随机推荐
Scratch Castle Adventure Electronic Society graphical programming scratch grade examination level 3 true questions and answers analysis June 2022
Industrial Internet has greater development potential and more industry scenarios
10. (map data) offline terrain data processing (for cesium)
Ml: introduction, principle, use method and detailed introduction of classic cases of snap value
leetcode:6110. 网格图中递增路径的数目【dfs + cache】
Leetcode t47: full arrangement II
Summary of common problems in development
C language small commodity management system
Detailed analysis of pytorch's automatic derivation mechanism, pytorch's core magic
C language personal address book management system
Expose Ali's salary and position level
Node mongodb installation
C language set operation
Digi重启XBee-Pro S2C生产,有些差别需要注意
Digi XBee 3 RF: 4个协议,3种封装,10个大功能
LVGL 8.2 Menu
remount of the / superblock failed: Permission denied
LVGL 8.2 keyboard
Abnormal value detection using shap value
Solutions to the problems of miui12.5 red rice k20pro using Au or povo2