LeetCode - Algorithms - 1365. How Many Numbers Are Smaller Than the Current Number

Problem

1365. How Many Numbers Are Smaller Than the Current Number

Java

1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class Solution {
public int[] smallerNumbersThanCurrent(int[] nums) {
final int N = nums.length;
int[] arr = new int[N];
for(int i=0;i<N;i++)
arr[i]=nums[i];
Arrays.sort(arr);
int[] r = new int[N];
for(int i=0;i<N;i++) {
int n = 0;
for(int j=0;j<N && arr[j]<nums[i];j++) {
n++;
}
r[i] = n;
}
return r;
}
}

Submission Detail

  • 103 / 103 test cases passed.
  • Runtime: 4 ms, faster than 66.15% of Java online submissions for How Many Numbers Are Smaller Than the Current Number.
  • Memory Usage: 38.8 MB, less than 84.14% of Java online submissions for How Many Numbers Are Smaller Than the Current Number.