-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathLeetcode_1365.java
38 lines (32 loc) · 1.06 KB
/
Leetcode_1365.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
public class Leetcode_1365 {
public static void main(String[] args) {
int[] nums = { 8, 1, 2, 2, 3 };
int[] result = smallerNumbersThanCurrent(nums);
for (int i : result) {
System.out.println(i);
}
}
public static int[] smallerNumbersThanCurrent(int[] nums) {
int[] copiedArray = nums.clone();
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
Arrays.sort(nums);
int result;
for (int i = nums.length - 1; i >= 0; i--) {
result = i;
map.put(nums[i], result);
}
// System.out.println(entry.getKey() + ":" + entry.getValue());
int[] output = new int[copiedArray.length];
for (int i = 0; i < copiedArray.length; i++) {
int value = map.get(copiedArray[i]);
output[i] = value;
}
return output;
}
}