当前位置:网站首页>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;
}
}
边栏推荐
- 联合索引的左匹配原则
- Past and present lives of QR code and sorting out six test points
- JDBC Requset 对应内容及功能介绍
- 还在为如何编写Web自动化测试用例而烦恼嘛?资深测试工程师手把手教你Selenium 测试用例编写
- 【无App Push 通用测试方案
- Basic knowledge of error
- 模拟卷Leetcode【普通】1414. 和为 K 的最少斐波那契数字数目
- 全程实现单点登录功能和请求被取消报错“cancelToken“ of undefined的解决方法
- Isam2 operation process
- LeetCode 732. 我的日程安排表 III
猜你喜欢
Caused by:org. gradle. api. internal. plugins . PluginApplicationException: Failed to apply plugin
ICLR 2022 spotlight | analog transformer: time series anomaly detection method based on correlation difference
基于JEECG-BOOT的list页面的地址栏参数传递
win10无法操作(删除、剪切)文件
[postman] the monitors monitoring API can run periodically
Pat (Grade B) 2022 summer exam
Technology sharing | common interface protocol analysis
[wechat applet] build a development tool environment
【Postman】测试(Tests)脚本编写和断言详解
【MQTT从入门到提高系列 | 01】从0到1快速搭建MQTT测试环境
随机推荐
黑猫带你学UFS协议第8篇:UFS初始化详解(Boot Operation)
【无App Push 通用测试方案
G - Supermarket
LeetCode 739. 每日温度
Aike AI frontier promotion (2.13)
Hypothesis testing learning notes
B - The Suspects
Delete the variables added to watch1 in keil MDK
MySQL之数据类型
Avtiviti创建表时报错:Error getting a new connection. Cause: org.apache.commons.dbcp.SQLNestedException
Thoughts on data security (Reprint)
模拟卷Leetcode【普通】1061. 按字典序排列最小的等效字符串
The latest 2022 review of "graph classification research"
MFC on the conversion and display of long string unsigned char and CString
對數據安全的思考(轉載)
QT: the program input point xxxxx cannot be located in the dynamic link library.
(中)苹果有开源,但又怎样呢?
测试周期被压缩?教你9个方法去应对
Customize the gateway filter factory on the specified route
leetcode 24. 两两交换链表中的节点