Skip to content

Commit dac1f92

Browse files
committed
Add solution #1365
1 parent 9d1e97c commit dac1f92

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@
142142
1351|[Count Negative Numbers in a Sorted Matrix](./1351-count-negative-numbers-in-a-sorted-matrix.js)|Easy|
143143
1356|[Sort Integers by The Number of 1 Bits](./1356-sort-integers-by-the-number-of-1-bits.js)|Easy|
144144
1360|[Number of Days Between Two Dates](./1360-number-of-days-between-two-dates.js)|Easy|
145+
1365|[How Many Numbers Are Smaller Than the Current Number](./1365-how-many-numbers-are-smaller-than-the-current-number.js)|Easy|
145146
1380|[Lucky Numbers in a Matrix](./1380-lucky-numbers-in-a-matrix.js)|Easy|
146147
1472|[Design Browser History](./1472-design-browser-history.js)|Medium|
147148
1598|[Crawler Log Folder](./1598-crawler-log-folder.js)|Easy|
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* 1365. How Many Numbers Are Smaller Than the Current Number
3+
* https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number/
4+
* Difficulty: Easy
5+
*
6+
* Given the array nums, for each nums[i] find out how many numbers in the array are smaller
7+
* than it. That is, for each nums[i] you have to count the number of valid j's such that
8+
* j != i and nums[j] < nums[i].
9+
*
10+
* Return the answer in an array.
11+
*/
12+
13+
/**
14+
* @param {number[]} nums
15+
* @return {number[]}
16+
*/
17+
var smallerNumbersThanCurrent = function(nums) {
18+
const sorted = nums.slice().sort((a, b) => a - b);
19+
return nums.map(num => sorted.indexOf(num));
20+
};

0 commit comments

Comments
 (0)