当前位置:网站首页>2022.7.4-----leetcode. one thousand and two hundred
2022.7.4-----leetcode. one thousand and two hundred
2022-07-05 08:28:00 【Lu 727】
public List<List<Integer>> minimumAbsDifference(int[] arr) {
int n=arr.length;
List<List<Integer>> ans=new ArrayList<>();
Arrays.sort(arr);
int min=Integer.MAX_VALUE;
for(int i=1;i<n;i++){
if(arr[i]-arr[i-1]<min){
ans.clear();
List<Integer> tmp=new ArrayList<>();
tmp.add(arr[i-1]);
tmp.add(arr[i]);
ans.add(tmp);
min=arr[i]-arr[i-1];
}else if(arr[i]-arr[i-1]==min){
List<Integer> tmp=new ArrayList<>();
tmp.add(arr[i-1]);
tmp.add(arr[i]);
ans.add(tmp);
}
}
return ans;
}
边栏推荐
- Various types of questions judged by prime numbers within 100 (C language)
- Bluebridge cup internet of things basic graphic tutorial - GPIO output control LD5 on and off
- Example 008: 99 multiplication table
- Bluebridge cup internet of things basic graphic tutorial - GPIO input key control LD5 on and off
- Semiconductor devices (I) PN junction
- 第十八章 使用工作队列管理器(一)
- Arduino uses nrf24l01+ communication
- Go dependency injection -- Google open source library wire
- How to write cover letter?
- Is the security account given by Yixue school safe? Where can I open an account
猜你喜欢
Simple design description of MIC circuit of ECM mobile phone
STM32 single chip microcomputer -- debug in keil5 cannot enter the main function
每日一题——输入一个日期,输出它是该年的第几天
【云原生 | 从零开始学Kubernetes】三、Kubernetes集群管理工具kubectl
实例007:copy 将一个列表的数据复制到另一个列表中。
[nas1] (2021cvpr) attentivenas: improving neural architecture search via attentive sampling (unfinished)
On boost circuit
Arduino uses nrf24l01+ communication
Nb-iot technical summary
MHA High available Cluster for MySQL
随机推荐
MySQL之MHA高可用集群
实例006:斐波那契数列
Nb-iot technical summary
Simple design description of MIC circuit of ECM mobile phone
[trio basic from introduction to mastery tutorial XIV] trio realizes unit axis multi-color code capture
QEMU STM32 vscode debugging environment configuration
Management and use of DokuWiki (supplementary)
STM32 --- configuration of external interrupt
Weidongshan Internet of things learning lesson 1
Sword finger offer 09 Implementing queues with two stacks
Stablq of linked list
Naming rules for FreeRTOS
Buildroot system for making raspberry pie cm3
Hardware 3 -- function of voltage follower
Charge pump boost principle - this article will give you a simple understanding
FIO测试硬盘性能参数和实例详细总结(附源码)
My-basic application 1: introduction to my-basic parser
99 multiplication table (C language)
Explication de la procédure stockée pour SQL Server
Array integration initialization (C language)