当前位置:网站首页>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;
}
}
边栏推荐
- High quality coding tool clion
- [untitled]
- 10M25DCF484C8G(FPGA) AMY-6M-0002 BGA GPS模块
- 公司视频加速播放
- 對數據安全的思考(轉載)
- Amazon Engineer: eight important experiences I learned in my career
- Buuctf-[[gwctf 2019] I have a database (xiaoyute detailed explanation)
- Construction of yolox based on paste framework
- Novice entry SCM must understand those things
- Manhattan distance sum - print diamond
猜你喜欢

養了只小猫咪

Application du Groupe Li dans gtsam

Wib3.0 leapfrogging, in leapfrogging (ง • ̀_•́) ง

Network protocol model

LAN communication process in the same network segment

Analysis report on development trends and investment planning of China's methanol industry from 2022 to 2028

数字三角形模型 AcWing 1015. 摘花生

单元测试的意义

Request forwarding and redirection

Configuring OSPF GR features for Huawei devices
随机推荐
OSPF configuration command of Huawei equipment
LAN communication process in the same network segment
[C language syntax] the difference between typedef struct and struct
VINS-Mono: A Robust and Versatile Monocular Visual-Inertial State Estimator
Fault, error, failure of functional safety
关于 PHP 启动 MongoDb 找不到指定模块问题
【C语言】qsort函数
Yunxiaoduo software internal test distribution test platform description document
LTE CSFB process
High quality coding tool clion
华为BFD的配置规范
ICLR 2022 spotlight | analog transformer: time series anomaly detection method based on correlation difference
Eigen sparse matrix operation
Nodejs realizes the third-party login of Weibo
Grant Yu, build a web page you want from 0
[happy Spring Festival] if you feel happy, dance
(5) Explanation of yolo-v3 core source code (3)
[web security] nodejs prototype chain pollution analysis
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
Redis6 cluster setup