Skip to content

Commit 21dd005

Browse files
committed
Add solution #1636
1 parent da71f89 commit 21dd005

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,437 LeetCode solutions in JavaScript
1+
# 1,438 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1260,6 +1260,7 @@
12601260
1630|[Arithmetic Subarrays](./solutions/1630-arithmetic-subarrays.js)|Medium|
12611261
1631|[Path With Minimum Effort](./solutions/1631-path-with-minimum-effort.js)|Medium|
12621262
1632|[Rank Transform of a Matrix](./solutions/1632-rank-transform-of-a-matrix.js)|Hard|
1263+
1636|[Sort Array by Increasing Frequency](./solutions/1636-sort-array-by-increasing-frequency.js)|Easy|
12631264
1657|[Determine if Two Strings Are Close](./solutions/1657-determine-if-two-strings-are-close.js)|Medium|
12641265
1668|[Maximum Repeating Substring](./solutions/1668-maximum-repeating-substring.js)|Easy|
12651266
1669|[Merge In Between Linked Lists](./solutions/1669-merge-in-between-linked-lists.js)|Medium|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* 1636. Sort Array by Increasing Frequency
3+
* https://leetcode.com/problems/sort-array-by-increasing-frequency/
4+
* Difficulty: Easy
5+
*
6+
* Given an array of integers nums, sort the array in increasing order based on the frequency
7+
* of the values. If multiple values have the same frequency, sort them in decreasing order.
8+
*
9+
* Return the sorted array.
10+
*/
11+
12+
/**
13+
* @param {number[]} nums
14+
* @return {number[]}
15+
*/
16+
var frequencySort = function(nums) {
17+
const map = new Map();
18+
nums.forEach(num => map.set(num, (map.get(num) || 0) + 1));
19+
20+
return nums.sort((a, b) => {
21+
const freqA = map.get(a);
22+
const freqB = map.get(b);
23+
return freqA === freqB ? b - a : freqA - freqB;
24+
});
25+
};

0 commit comments

Comments
 (0)