Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9e90e95

Browse files
refactor 1120
1 parent65dfa4b commit9e90e95

File tree

1 file changed

+1
-27
lines changed

1 file changed

+1
-27
lines changed

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

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,12 @@
44
importjava.util.Arrays;
55
importjava.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
publicclass_1200 {
348
publicstaticclassSolution1 {
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
publicList<List<Integer>>minimumAbsDifference(int[]arr) {
4014
Arrays.sort(arr);
4115
intminimumDiff =arr[1] -arr[0];

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp