File tree 2 files changed +27
-1
lines changed
2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,437 LeetCode solutions in JavaScript
1
+ # 1,438 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
1260
1260
1630|[ Arithmetic Subarrays] ( ./solutions/1630-arithmetic-subarrays.js ) |Medium|
1261
1261
1631|[ Path With Minimum Effort] ( ./solutions/1631-path-with-minimum-effort.js ) |Medium|
1262
1262
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|
1263
1264
1657|[ Determine if Two Strings Are Close] ( ./solutions/1657-determine-if-two-strings-are-close.js ) |Medium|
1264
1265
1668|[ Maximum Repeating Substring] ( ./solutions/1668-maximum-repeating-substring.js ) |Easy|
1265
1266
1669|[ Merge In Between Linked Lists] ( ./solutions/1669-merge-in-between-linked-lists.js ) |Medium|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments