当前位置:网站首页>LeetCode 1200. Minimum absolute difference
LeetCode 1200. Minimum absolute difference
2022-07-06 06:23:00 【Sasakihaise_】
1200. Minimum absolute difference
【 analysis 】 Judge after sorting .
List and Set Empty available clear Or just re new One , The efficiency of the two is the same .
However, it should be noted that when defining a large value, it is best to use (int)1e9 such , Do not use 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;
}
}
边栏推荐
- [C language] string left rotation
- 二维码的前世今生 与 六大测试点梳理
- Database - current read and snapshot read
- Black cat takes you to learn UFS protocol Chapter 18: how UFS configures logical units (Lu Management)
- JWT-JSON WEB TOKEN
- B - The Suspects
- Selenium source code read through · 9 | desiredcapabilities class analysis
- Delete the variables added to watch1 in keil MDK
- Manage configuration using Nacos
- MFC on the conversion and display of long string unsigned char and CString
猜你喜欢
【Tera Term】黑猫带你学TTL脚本——嵌入式开发中串口自动化神技能
On weak network test of special test
ESP32 ESP-IDF看门狗TWDT
The whole process realizes the single sign on function and the solution of "canceltoken" of undefined when the request is canceled
MySQL之数据类型
基于JEECG-BOOT的list页面的地址栏参数传递
黑猫带你学UFS协议第4篇:UFS协议栈详解
Detailed explanation of P problem, NP problem, NPC problem and NP hard problem
D - How Many Answers Are Wrong
Technology sharing | common interface protocol analysis
随机推荐
[no app push general test plan
Simulation volume leetcode [general] 1414 The minimum number of Fibonacci numbers with a sum of K
曼哈顿距离和-打印菱形
[eolink] PC client installation
模拟卷Leetcode【普通】1061. 按字典序排列最小的等效字符串
Réflexions sur la sécurité des données (réimpression)
Online and offline problems
【Postman】动态变量(也称Mock函数)
leetcode 24. 两两交换链表中的节点
Simulation volume leetcode [general] 1219 Golden Miner
G - Supermarket
Avtiviti创建表时报错:Error getting a new connection. Cause: org.apache.commons.dbcp.SQLNestedException
数据库-当前读与快照读
私人云盘部署
G - Supermarket
php使用redis实现分布式锁
Left matching principle of joint index
The latest 2022 review of "graph classification research"
Set the print page style by modifying style
[Tera term] black cat takes you to learn TTL script -- serial port automation skill in embedded development