当前位置:网站首页>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;
}
边栏推荐
- Step motor generates S-curve upper computer
- Example 001: the number combination has four numbers: 1, 2, 3, 4. How many three digits can be formed that are different from each other and have no duplicate numbers? How many are each?
- Compilation warning solution sorting in Quartus II
- Brief discussion on Buck buck circuit
- Bluebridge cup internet of things basic graphic tutorial - GPIO output control LD5 on and off
- Google sitemap files for rails Projects - Google sitemap files for rails projects
- What are the test items of power battery ul2580
- Design a clock frequency division circuit that can be switched arbitrarily
- [cloud native | learn kubernetes from scratch] III. kubernetes cluster management tool kubectl
- Several implementation schemes of anti reverse connection protection of positive and negative poles of power supply!
猜你喜欢
Simple design description of MIC circuit of ECM mobile phone
实例009:暂停一秒输出
【论文阅读】2022年最新迁移学习综述笔注(Transferability in Deep Learning: A Survey)
Relationship between line voltage and phase voltage, line current and phase current
Example 007: copy data from one list to another list.
Stablq of linked list
[three tier architecture]
Hardware 3 -- function of voltage follower
实例010:给人看的时间
DCDC circuit - function of bootstrap capacitor
随机推荐
Example 006: Fibonacci series
Soem EtherCAT source code analysis attachment 1 (establishment of communication operation environment)
Naming rules for FreeRTOS
STM32 --- NVIC interrupt
Shell script realizes the reading of serial port and the parsing of message
Example 007: copy data from one list to another list.
[trio basic tutorial 17 from getting started to mastering] set up and connect the trio motion controller and input the activation code
[three tier architecture and JDBC summary]
Bootloader implementation of PIC MCU
Talk about the circuit use of TVs tube
Buildroot system for making raspberry pie cm3
Introduction of air gap, etc
Void* C is a carrier for realizing polymorphism
99 multiplication table (C language)
Relationship between line voltage and phase voltage, line current and phase current
Example 005: three numbers sorting input three integers x, y, Z, please output these three numbers from small to large.
My-basic application 2: my-basic installation and operation
实例005:三数排序 输入三个整数x,y,z,请把这三个数由小到大输出。
实例004:这天第几天 输入某年某月某日,判断这一天是这一年的第几天?
Sword finger offer 09 Implementing queues with two stacks