当前位置:网站首页>Force buckle 1200 Minimum absolute difference
Force buckle 1200 Minimum absolute difference
2022-07-05 19:28:00 【Ruthless young Fisherman】
subject
Here's an array of integers arr, Each of these elements is inequality .
Please find all the elements with the least absolute difference , And return in ascending order .
Example
Input :arr = [4,2,1,3]
Output :[[1,2],[2,3],[3,4]]
Input :arr = [1,3,6,10,15]
Output :[[1,3]]
Input :arr = [3,8,-10,23,19,-4,-14,27]
Output :[[-14,-10],[19,23],[23,27]]
source : Power button (LeetCode)
link :https://leetcode.cn/problems/minimum-absolute-difference
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
Method 1: simulation
Java Realization
class Solution {
public List<List<Integer>> minimumAbsDifference(int[] arr) {
int n = arr.length;
Arrays.sort(arr);
List<List<Integer>> res = new ArrayList<>();
int min = Integer.MAX_VALUE;
for (int i = 0; i < n - 1; i++) {
int cur = Math.abs(arr[i] - arr[i + 1]);
if (cur == min) {
res.add(Arrays.asList(arr[i], arr[i + 1]));
} else if (cur < min) {
min = cur;
res = new ArrayList<>();
res.add(Arrays.asList(arr[i], arr[i + 1]));
}
}
return res;
}
}

边栏推荐
- The relationship between temperature measurement and imaging accuracy of ifd-x micro infrared imager (module)
- Realizing deep learning framework from zero -- LSTM from theory to practice [practice]
- PHP uses ueditor to upload pictures and add watermarks
- Go语言 | 03 数组、指针、切片用法
- Reptile exercises (II)
- 大厂面试必备技能,2022Android不死我不倒
- How about testing outsourcing companies?
- Tutoriel de téléchargement et d'installation du progiciel fuzor 2020
- 什么是面上项目
- How to apply smart contracts more wisely in 2022?
猜你喜欢

基于FPGA的超声波测距

Fuzor 2020軟件安裝包下載及安裝教程

建议收藏,我的腾讯Android面试经历分享

IFD-x 微型红外成像仪(模块)关于温度测量和成像精度的关系

详解SQL中Groupings Sets 语句的功能和底层实现逻辑

Worthy of being a boss, byte Daniel spent eight months on another masterpiece

5 years of experience, 27 days of Android programmer interview, 2022 programmer advanced classic

Advanced application of C # language

微波雷达感应模块技术,实时智能检测人体存在,静止微小动静感知

【合集- 行业解决方案】如何搭建高性能的数据加速与数据编排平台
随机推荐
基于FPGA的超声波测距
Postman core function analysis - parameterization and test report
That's awesome. It's enough to read this article
Postman核心功能解析-参数化和测试报告
安卓面试宝典,2022Android面试笔试总结
After the company went bankrupt, the blackstones came
【obs】libobs-winrt :CreateDispatcherQueueController
Notion 类生产力工具如何选择?Notion 、FlowUs 、Wolai 对比评测
HAC cluster modifying administrator user password
Password reset of MariaDB root user and ordinary user
okcc呼叫中心有什么作用
MMO項目學習一:預熱
【硬核干货】数据分析哪家强?选Pandas还是选SQL
Apprentissage du projet MMO I: préchauffage
Hiengine: comparable to the local cloud native memory database engine
Explain in detail the functions and underlying implementation logic of the groups sets statement in SQL
在线协作产品哪家强?微软 Loop 、Notion、FlowUs
XaaS 陷阱:万物皆服务(可能)并不是IT真正需要的东西
Debezium系列之:postgresql从偏移量加载正确的最后一次提交 LSN
Mariadb root用户及普通用户的密码 重置