当前位置:网站首页>LeetCode 1200. 最小绝对差
LeetCode 1200. 最小绝对差
2022-07-06 06:02:00 【Sasakihaise_】

【分析】排序后判断即可。
List和Set清空可以用clear或者直接重新new一个,二者效率相差无异。
但是需要注意定义一个较大值的时候最好用(int)1e9这种,不要用1<<30。
class Solution {
public List<List<Integer>> minimumAbsDifference(int[] arr) {
Arrays.sort(arr);
List<List<Integer>> ans = new ArrayList();
int min = (int)1e7;
for (var i = 1; i < arr.length; i++) {
int t = arr[i] - arr[i - 1];
if (t < min) {
min = t;
ans.clear();
}
if (t == min) {
ArrayList<Integer> pair = new ArrayList();
pair.add(arr[i - 1]);
pair.add(arr[i]);
ans.add(pair);
}
}
return ans;
}
}
边栏推荐
- Title 1093: character reverse order
- ICLR 2022 spotlight | analog transformer: time series anomaly detection method based on correlation difference
- 公司視頻加速播放
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- 【无标题】
- Eigen sparse matrix operation
- The latest 2022 review of "graph classification research"
- 【API接口工具】postman-界面使用介绍
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- 对数据安全的思考(转载)
猜你喜欢

【课程笔记】编译原理

关于 PHP 启动 MongoDb 找不到指定模块问题

The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower

The latest 2022 review of "graph classification research"

C language bubble sort

请求转发与重定向

SQLMAP使用教程(三)实战技巧二

【无标题】

如何在业务代码中使用 ThinkPHP5.1 封装的容器内反射方法
![[happy Spring Festival] if you feel happy, dance](/img/b5/faa4cb94ef5fb45b8bb98ecb69962f.jpg)
[happy Spring Festival] if you feel happy, dance
随机推荐
Basic knowledge of error
Arrays and collections
【Postman】Monitors 监测API可定时周期运行
Leetcode 701 insertion operation in binary search tree -- recursive method and iterative method
假设检验学习笔记
Database: ODBC remote access SQL Server2008 in oracel
误差的基本知识
数字三角形模型 AcWing 1015. 摘花生
【Postman】Collections-运行配置之导入数据文件
[C language syntax] the difference between typedef struct and struct
c语言——冒泡排序
Memory and stack related concepts
异常检测方法总结
[web security] nodejs prototype chain pollution analysis
PAT(乙级)2022年夏季考试
局域网同一个网段通信过程
公司視頻加速播放
P问题、NP问题、NPC问题、NP-hard问题详解
Company video accelerated playback
My 2021