当前位置:网站首页>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;
}
}
边栏推荐
- CoordinatorLayout+NestedScrollView+RecyclerView 上拉底部显示不全
- HCIA review
- Clock in during winter vacation
- Yunxiaoduo software internal test distribution test platform description document
- LeetCode 732. 我的日程安排表 III
- 【C语言】字符串左旋
- 华为BFD的配置规范
- Baidu online AI competition - image processing challenge: the 8th program of handwriting erasure
- Expose the serial fraudster Liu Qing in the currency circle, and default hundreds of millions of Cheng Laolai
- Linux regularly backs up MySQL database
猜你喜欢

properties文件

HCIA复习

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

Memory and stack related concepts

Usage of test macro of GTEST

VINS-Mono: A Robust and Versatile Monocular Visual-Inertial State Estimator

Database: ODBC remote access SQL Server2008 in oracel

【API接口工具】postman-界面使用介绍

10M25DCF484C8G(FPGA) AMY-6M-0002 BGA GPS模块

The usage and difference between strlen and sizeof
随机推荐
关于 PHP 启动 MongoDb 找不到指定模块问题
OSPF configuration command of Huawei equipment
leaflet 地图
Hypothesis testing learning notes
【论文阅读】NFlowJS:基于鲁棒学习的合成负数据密集异常检测
【微信小程序】搭建开发工具环境
曼哈顿距离与曼哈顿矩形-打印回字型矩阵
My 2021
Significance of unit testing
Huawei BFD configuration specification
Summary of data sets in intrusion detection field
假设检验学习笔记
Cognitive introspection
H3C V7版本交换机配置IRF
對數據安全的思考(轉載)
Interface test: what are the components of the URL in fiddler
GTSAM中李群的運用
ICLR 2022 spotlight | analog transformer: time series anomaly detection method based on correlation difference
[ram IP] introduction and experiment of ram IP core
数字三角形模型 AcWing 1015. 摘花生