当前位置:网站首页>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;
}边栏推荐
- MySQL之MHA高可用集群
- Sword finger offer 06 Print linked list from end to end
- Soem EtherCAT source code analysis I (data type definition)
- Imx6ull bare metal development learning 1-assembly lit LED
- Briefly talk about the identification protocol of mobile port -bc1.2
- 每日一题——替换空格
- 实例004:这天第几天 输入某年某月某日,判断这一天是这一年的第几天?
- Take you to understand the working principle of lithium battery protection board
- Example 003: a complete square is an integer. It is a complete square after adding 100, and it is a complete square after adding 168. What is the number?
- [trio basic from introduction to mastery tutorial XIV] trio realizes unit axis multi-color code capture
猜你喜欢

MHA High available Cluster for MySQL

实例003:完全平方数 一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?

Introduction of air gap, etc

Management and use of DokuWiki
![[cloud native | learn kubernetes from scratch] III. kubernetes cluster management tool kubectl](/img/8a/702019b44c8e60dffbcd898330afcb.png)
[cloud native | learn kubernetes from scratch] III. kubernetes cluster management tool kubectl

Solutions to compilation warnings in Quartus II

剑指 Offer 05. 替换空格

Take you to understand the working principle of lithium battery protection board
![[trio basic from introduction to mastery tutorial XIV] trio realizes unit axis multi-color code capture](/img/c5/22c6148873508b9205972e1ad970a3.jpg)
[trio basic from introduction to mastery tutorial XIV] trio realizes unit axis multi-color code capture

Example 005: three numbers sorting input three integers x, y, Z, please output these three numbers from small to large.
随机推荐
STM32 tutorial triple ADC interleaved sampling
Summary of SIM card circuit knowledge
Some thoughts on extracting perspectives from ealfa and Ebeta
Sql Server的存储过程详解
STM32 single chip microcomputer -- debug in keil5 cannot enter the main function
Solutions to compilation warnings in Quartus II
实例001:数字组合 有四个数字:1、2、3、4,能组成多少个互不相同且无重复数字的三位数?各是多少?
Stm32--- systick timer
Sword finger offer 06 Print linked list from end to end
[tutorial 15 of trio basic from introduction to proficiency] trio free serial communication
Classic application of MOS transistor circuit design (2) - switch circuit design
Semiconductor devices (III) FET
Example 005: three numbers sorting input three integers x, y, Z, please output these three numbers from small to large.
DCDC circuit - function of bootstrap capacitor
After installing the new version of keil5 or upgrading the JLINK firmware, you will always be prompted about the firmware update
STM32 single chip microcomputer - external interrupt
OC and OD gate circuit
Example 007: copy data from one list to another list.
[tutorial 19 of trio basic from introduction to proficiency] detailed introduction of trio as a slave station connecting to the third-party bus (anybus PROFIBUS DP...)
实例003:完全平方数 一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?