8000 Create 1365. How Many Numbers Are Smaller Than the Current Number · stutipandey20/Leetcode-Challenge@ceeba54 · GitHub
[go: up one dir, main page]

Skip to content

Commit ceeba54

Browse files
authored
Create 1365. How Many Numbers Are Smaller Than the Current Number
1 parent 526e91e commit ceeba54

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public int[] smallerNumbersThanCurrent(int[] nums) {
3+
int[] result = nums.clone();
4+
Arrays.sort(result);
5+
Map<Integer,Integer> index = new HashMap<>();
6+
for(int i=0;i<result.length;i++){
7+
index.putIfAbsent(result[i],i);
8+
}
9+
for(int i=0;i<nums.length;i++){
10+
result[i] = index.get(nums[i]);
11+
}
12+
return result;
13+
}
14+
}

0 commit comments

Comments
 (0)
0