当前位置:网站首页>LeetCode 1200. Minimum absolute difference
LeetCode 1200. Minimum absolute difference
2022-07-06 06:23:00 【Sasakihaise_】
1200. Minimum absolute difference

【 analysis 】 Judge after sorting .
List and Set Empty available clear Or just re new One , The efficiency of the two is the same .
However, it should be noted that when defining a large value, it is best to use (int)1e9 such , Do not use 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;
}
}
边栏推荐
- Summary of the post of "Web Test Engineer"
- 数据库隔离级别
- 使用Nacos管理配置
- 曼哈顿距离和-打印菱形
- 模拟卷Leetcode【普通】1062. 最长重复子串
- 模拟卷Leetcode【普通】1405. 最长快乐字符串
- 【无App Push 通用测试方案
- MFC on the conversion and display of long string unsigned char and CString
- [C language] qsort function
- Simulation volume leetcode [general] 1405 Longest happy string
猜你喜欢

全程实现单点登录功能和请求被取消报错“cancelToken“ of undefined的解决方法

G - Supermarket

曼哈顿距离和-打印菱形

Pat (Grade B) 2022 summer exam

B - The Suspects

ICLR 2022 spotlight | analog transformer: time series anomaly detection method based on correlation difference
![[postman] collections configuration running process](/img/09/bcd9fd6379fa724671ffd09278442e.png)
[postman] collections configuration running process

LeetCode 1200. 最小绝对差

mysql按照首字母排序
![[wechat applet] build a development tool environment](/img/f6/51f97b1c927337b34c5b3a4207abb4.png)
[wechat applet] build a development tool environment
随机推荐
[wechat applet] build a development tool environment
G - Supermarket
Past and present lives of QR code and sorting out six test points
[C language] string left rotation
Basic knowledge of error
Play video with Tencent video plug-in in uni app
Nodejs realizes the third-party login of Weibo
模拟卷Leetcode【普通】1447. 最简分数
leetcode 24. 两两交换链表中的节点
对数据安全的思考(转载)
Data type of MySQL
E - food chain
模拟卷Leetcode【普通】1249. 移除无效的括号
黑猫带你学UFS协议第18篇:UFS如何配置逻辑单元(LU Management)
黑猫带你学UFS协议第4篇:UFS协议栈详解
测试周期被压缩?教你9个方法去应对
[Tera term] black cat takes you to learn TTL script -- serial port automation skill in embedded development
D - How Many Answers Are Wrong
记一个基于JEECG-BOOT的比较复杂的增删改功能的实现
記一個基於JEECG-BOOT的比較複雜的增删改功能的實現