Skip to content

Commit 7e0fea9

Browse files
authored
Create 1365-how-many-numbers-are-smaller-than-the-current-number.js
1 parent 84673bb commit 7e0fea9

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {number[]}
4+
*/
5+
const smallerNumbersThanCurrent = function(nums) {
6+
const count = new Array(101).fill(0);
7+
const res = new Array(nums.length).fill(0);
8+
for (let i = 0; i < nums.length; i++) count[nums[i]]++
9+
for (let i = 1 ; i <= 100; i++) count[i] += count[i-1]
10+
for (let i = 0; i < nums.length; i++) {
11+
if (nums[i] == 0) res[i] = 0
12+
else res[i] = count[nums[i] - 1]
13+
}
14+
return res;
15+
};
16+

0 commit comments

Comments
 (0)