-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHowManyNumbers.java
More file actions
24 lines (23 loc) · 743 Bytes
/
HowManyNumbers.java
File metadata and controls
24 lines (23 loc) · 743 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package leetcode.array;
/**
* @ClassName HowManyNumbers
* @Description 有多少小于当前数字的数字 https://leetcode-cn.com/problems/how-many-numbers-are-smaller-than-the-current-number/
* @Author changxuan
* @Date 2020/10/26 下午9:21
**/
public class HowManyNumbers {
public int[] smallerNumbersThanCurrent(int[] nums) {
int[] count = new int[101];
for (int i = 0; i < nums.length; i++) {
count[nums[i]]++;
}
for (int i = 1; i <= 100; i++) {
count[i] += count[i-1];
}
int[] res = new int[nums.length];
for (int i = 0; i < nums.length; i++) {
res[i] = nums[i] == 0 ? 0 : (count[nums[i] - 1]);
}
return res;
}
}