当前位置:网站首页>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;
}
}
边栏推荐
猜你喜欢

LeetCode 739. 每日温度

Selenium source code read through · 9 | desiredcapabilities class analysis

私人云盘部署

Delete the variables added to watch1 in keil MDK

F - True Liars (种类并查集+DP)

Understanding of processes and threads

10m25dcf484c8g (FPGA) amy-6m-0002 BGA GPS module

Coordinatorlayout+nestedscrollview+recyclerview pull up the bottom display is incomplete

【Tera Term】黑猫带你学TTL脚本——嵌入式开发中串口自动化神技能

Past and present lives of QR code and sorting out six test points
随机推荐
Understanding of processes and threads
Simulation volume leetcode [general] 1062 Longest repeating substring
[postman] the monitors monitoring API can run periodically
The whole process realizes the single sign on function and the solution of "canceltoken" of undefined when the request is canceled
Simulation volume leetcode [general] 1314 Matrix area and
Online and offline problems
php使用redis实现分布式锁
win10无法操作(删除、剪切)文件
ESP32 ESP-IDF看门狗TWDT
Simulation volume leetcode [general] 1218 Longest definite difference subsequence
Leaflet map
模拟卷Leetcode【普通】1109. 航班预订统计
Cannot create poolableconnectionfactory (could not create connection to database server. error
LeetCode 739. 每日温度
Coordinatorlayout+nestedscrollview+recyclerview pull up the bottom display is incomplete
Caused by:org. gradle. api. internal. plugins . PluginApplicationException: Failed to apply plugin
Selenium source code read through · 9 | desiredcapabilities class analysis
记一个基于JEECG-BOOT的比较复杂的增删改功能的实现
模拟卷Leetcode【普通】1062. 最长重复子串
通过修改style设置打印页样式