当前位置:网站首页>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;
}
边栏推荐
- 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?
- Soem EtherCAT source code analysis I (data type definition)
- Zero length array in GNU C
- MySQL MHA high availability cluster
- 实例004:这天第几天 输入某年某月某日,判断这一天是这一年的第几天?
- Compilation warning solution sorting in Quartus II
- 实例007:copy 将一个列表的数据复制到另一个列表中。
- 剑指 Offer 05. 替换空格
- Sword finger offer 09 Implementing queues with two stacks
- Brief discussion on Buck buck circuit
猜你喜欢
Example 002: the bonus paid by the "individual income tax calculation" enterprise is based on the profit commission. When the profit (I) is less than or equal to 100000 yuan, the bonus can be increase
剑指 Offer 05. 替换空格
Classic application of MOS transistor circuit design (2) - switch circuit design
实例002:“个税计算” 企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%;利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可提成7.
[trio basic tutorial 17 from getting started to mastering] set up and connect the trio motion controller and input the activation code
leetcode - 445. Add two numbers II
如何写Cover Letter?
【三层架构及JDBC总结】
Sword finger offer 05 Replace spaces
MySQL MHA high availability cluster
随机推荐
Compilation warning solution sorting in Quartus II
[trio basic from introduction to mastery tutorial 20] trio calculates the arc center and radius through three points of spatial arc
Sword finger offer 09 Implementing queues with two stacks
What are the test items of power battery ul2580
[paper reading] the latest transfer ability in deep learning: a survey in 2022
Tailq of linked list
Soem EtherCAT source code analysis I (data type definition)
General makefile (I) single C language compilation template
Nb-iot technical summary
Why is 1900 not a leap year
[trio basic from introduction to mastery tutorial XIV] trio realizes unit axis multi-color code capture
Briefly talk about the identification protocol of mobile port -bc1.2
Live555 push RTSP audio and video stream summary (III) flower screen problem caused by pushing H264 real-time stream
【论文阅读】2022年最新迁移学习综述笔注(Transferability in Deep Learning: A Survey)
Ble encryption details
Live555 push RTSP audio and video stream summary (I) cross compilation
Problem solving: interpreter error: no file or directory
OC and OD gate circuit
Bootloader implementation of PIC MCU
Solutions to compilation warnings in Quartus II