Skip to content

Commit 9e90e95

Browse files
refactor 1120
1 parent 65dfa4b commit 9e90e95

File tree

1 file changed

+1
-27
lines changed

1 file changed

+1
-27
lines changed

src/main/java/com/fishercoder/solutions/_1200.java

+1-27
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,12 @@
44
import java.util.Arrays;
55
import java.util.List;
66

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-
* */
337
public class _1200 {
348
public static class Solution1 {
359
/**
3610
* Time: O(nlogn) due to sorting
3711
* Space: O(k) where k is the distinct number of differences between two numbers in the given array
38-
* */
12+
*/
3913
public List<List<Integer>> minimumAbsDifference(int[] arr) {
4014
Arrays.sort(arr);
4115
int minimumDiff = arr[1] - arr[0];

0 commit comments

Comments
 (0)