Skip to content

Commit d9ab7dc

Browse files
committed
✨ [1365]
1 parent 21065cd commit d9ab7dc

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

1365/my_solution.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,28 @@
33
* @return {number[]}
44
*/
55
const smallerNumbersThanCurrent = (nums) => {
6-
6+
console.log((nums))
7+
console.log(Math.max(...nums))
8+
let bucket = Array(Math.max(...nums) + 1).fill(0);
9+
console.log(bucket)
10+
11+
for (let i = 0; i < nums.length; i++) {
12+
bucket[nums[i]]++;
13+
}
14+
15+
for (let i = 1; i < bucket.length; i++) {
16+
bucket[i] += bucket[i - 1];
17+
}
18+
19+
let countList = [];
20+
for (let i = 0; i < nums.length; i++) {
21+
countList[i] = bucket[nums[i] - 1] || 0;
22+
}
23+
24+
return countList;
725
};
26+
27+
28+
// let x = smallerNumbersThanCurrent([8, 1, 2, 2, 3]);
29+
let x = smallerNumbersThanCurrent([5, 0, 10, 0, 10, 6]);
30+
console.log(x)

1365/solution.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {number[]}
4+
*/
5+
const smallerNumbersThanCurrent = (nums) => {
6+
let bucket = Array(Math.max(...nums) + 1).fill(0);
7+
8+
for (let i = 0; i < nums.length; i++) {
9+
bucket[nums[i]]++;
10+
}
11+
12+
for (let i = 1; i < bucket.length; i++) {
13+
bucket[i] += bucket[i - 1];
14+
}
15+
16+
let countList = [];
17+
for (let i = 0; i < nums.length; i++) {
18+
countList[i] = bucket[nums[i] - 1] || 0;
19+
}
20+
21+
return countList;
22+
};
23+

0 commit comments

Comments
 (0)