当前位置:网站首页>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;
}
}
边栏推荐
猜你喜欢
selenium源码通读·9 |DesiredCapabilities类分析
B - The Suspects
MySQL之数据类型
Properties file
Understanding of processes and threads
Data type of MySQL
记一个基于JEECG-BOOT的比较复杂的增删改功能的实现
Database isolation level
10m25dcf484c8g (FPGA) amy-6m-0002 BGA GPS module
org.activiti.bpmn.exceptions.XMLException: cvc-complex-type.2.4.a: 发现了以元素 ‘outgoing‘ 开头的无效内容
随机推荐
Hypothesis testing learning notes
曼哈顿距离与曼哈顿矩形-打印回字型矩阵
Simulation volume leetcode [general] 1062 Longest repeating substring
selenium源码通读·9 |DesiredCapabilities类分析
MySQL之数据类型
模拟卷Leetcode【普通】1109. 航班预订统计
Play video with Tencent video plug-in in uni app
记一个基于JEECG-BOOT的比较复杂的增删改功能的实现
leetcode 24. 两两交换链表中的节点
联合索引的左匹配原则
The whole process realizes the single sign on function and the solution of "canceltoken" of undefined when the request is canceled
MFC 动态创建的对话框及改变控件的大小和位置
Digital triangle model acwing 1015 Picking flowers
Is the test cycle compressed? Teach you 9 ways to deal with it
Avtiviti创建表时报错:Error getting a new connection. Cause: org.apache.commons.dbcp.SQLNestedException
Understanding of processes and threads
Réflexions sur la sécurité des données (réimpression)
基于JEECG-BOOT制作“左树右表”交互页面
模拟卷Leetcode【普通】1296. 划分数组为连续数字的集合
G - Supermarket