|
4 | 4 | import java.util.Arrays;
|
5 | 5 | import java.util.List;
|
6 | 6 |
|
7 |
| -/** |
8 |
| - * 1200. Minimum Absolute Difference |
9 |
| - * |
10 |
| - * Given an array of distinct integers arr, find all pairs of elements with the minimum absolute difference of any two elements. |
11 |
| - * Return a list of pairs in ascending order(with respect to pairs), each pair [a, b] follows |
12 |
| - * a, b are from arr |
13 |
| - * a < b |
14 |
| - * b - a equals to the minimum absolute difference of any two elements in arr |
15 |
| - * |
16 |
| - * Example 1: |
17 |
| - * Input: arr = [4,2,1,3] |
18 |
| - * Output: [[1,2],[2,3],[3,4]] |
19 |
| - * Explanation: The minimum absolute difference is 1. List all pairs with difference equal to 1 in ascending order. |
20 |
| - * |
21 |
| - * Example 2: |
22 |
| - * Input: arr = [1,3,6,10,15] |
23 |
| - * Output: [[1,3]] |
24 |
| - * |
25 |
| - * Example 3: |
26 |
| - * Input: arr = [3,8,-10,23,19,-4,-14,27] |
27 |
| - * Output: [[-14,-10],[19,23],[23,27]] |
28 |
| - * |
29 |
| - * Constraints: |
30 |
| - * 2 <= arr.length <= 10^5 |
31 |
| - * -10^6 <= arr[i] <= 10^6 |
32 |
| - * */ |
33 | 7 | public class _1200 {
|
34 | 8 | public static class Solution1 {
|
35 | 9 | /**
|
36 | 10 | * Time: O(nlogn) due to sorting
|
37 | 11 | * Space: O(k) where k is the distinct number of differences between two numbers in the given array
|
38 |
| - * */ |
| 12 | + */ |
39 | 13 | public List<List<Integer>> minimumAbsDifference(int[] arr) {
|
40 | 14 | Arrays.sort(arr);
|
41 | 15 | int minimumDiff = arr[1] - arr[0];
|
|
0 commit comments