# 1200. Minimum Absolute Difference ###### tags: `Leetcode` `Easy` Link: https://leetcode.com/problems/minimum-absolute-difference/ ## 思路 $O(NlogN)$ $O(1)$ 首先对array排序,然后首先找到最小的diff,然后再遍历一遍产生答案 ## Code ```java= class Solution { public List<List<Integer>> minimumAbsDifference(int[] arr) { Arrays.sort(arr); int diff = Integer.MAX_VALUE; for(int i = 0;i < arr.length-1;i++){ diff = Math.min(diff, arr[i+1]-arr[i]); } List<List<Integer>> ans = new ArrayList<>(); for(int i = 0;i < arr.length-1;i++){ if(arr[i+1]-arr[i]==diff){ List<Integer> temp = new ArrayList<>(); temp.add(arr[i]); temp.add(arr[i+1]); ans.add(temp); } } return ans; } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up