当前位置:网站首页>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;
}
}
边栏推荐
- Black cat takes you to learn UFS Protocol Part 8: UFS initialization (boot operation)
- 技术分享 | 常见接口协议解析
- 在JEECG-boot代码生成的基础上修改list页面(结合自定义的组件)
- org.activiti.bpmn.exceptions.XMLException: cvc-complex-type.2.4.a: 发现了以元素 ‘outgoing‘ 开头的无效内容
- 调用链监控Zipkin、sleuth搭建与整合
- 模拟卷Leetcode【普通】1061. 按字典序排列最小的等效字符串
- Is the test cycle compressed? Teach you 9 ways to deal with it
- How to extract login cookies when JMeter performs interface testing
- [API interface tool] Introduction to postman interface
- Simulation volume leetcode [general] 1143 Longest common subsequence
猜你喜欢

Postman核心功能解析-参数化和测试报告

进程和线程的理解

调用链监控Zipkin、sleuth搭建与整合

Database - current read and snapshot read

sourceInsight中文乱码

Avtiviti创建表时报错:Error getting a new connection. Cause: org.apache.commons.dbcp.SQLNestedException

Redis 核心技术与实战之 基本架构:一个键值数据库包含什么?

On weak network test of special test

Selenium source code read through · 9 | desiredcapabilities class analysis

黑猫带你学UFS协议第4篇:UFS协议栈详解
随机推荐
sourceInsight中文乱码
An article was uncovered to test the truth of outsourcing companies
Thoughts on data security (Reprint)
[postman] collections configuration running process
[C language] string left rotation
Full link voltage measurement: building three models
一文揭开,测试外包公司的真 相
【无App Push 通用测试方案
还在为如何编写Web自动化测试用例而烦恼嘛?资深测试工程师手把手教你Selenium 测试用例编写
Manhattan distance and Manhattan rectangle - print back font matrix
MySQL之基础知识
Customize the gateway filter factory on the specified route
Set the print page style by modifying style
B - The Suspects
Simulation volume leetcode [general] 1249 Remove invalid parentheses
LeetCode 1200. 最小绝对差
E - 食物链
leetcode 24. Exchange the nodes in the linked list in pairs
测试周期被压缩?教你9个方法去应对
org.activiti.bpmn.exceptions.XMLException: cvc-complex-type.2.4.a: 发现了以元素 ‘outgoing‘ 开头的无效内容