File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change 125
125
1324|[ Print Words Vertically] ( ./1324-print-words-vertically.js ) |Medium|
126
126
1332|[ Remove Palindromic Subsequences] ( ./1332-remove-palindromic-subsequences.js ) |Easy|
127
127
1333|[ Filter Restaurants by Vegan-Friendly, Price and Distance] ( ./1333-filter-restaurants-by-vegan-friendly-price-and-distance.js ) |Medium|
128
+ 1356|[ Sort Integers by The Number of 1 Bits] ( ./1356-sort-integers-by-the-number-of-1-bits.js ) |Easy|
128
129
1360|[ Number of Days Between Two Dates] ( ./1360-number-of-days-between-two-dates.js ) |Easy|
129
130
1472|[ Design Browser History] ( ./1472-design-browser-history.js ) |Medium|
130
131
1598|[ Crawler Log Folder] ( ./1598-crawler-log-folder.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 1356. Sort Integers by The Number of 1 Bits
3
+ * https://leetcode.com/problems/sort-integers-by-the-number-of-1-bits/
4
+ * Difficulty: Easy
5
+ *
6
+ * Given an integer array arr. You have to sort the integers in the array in
7
+ * ascending order by the number of 1's in their binary representation and
8
+ * in case of two or more integers have the same number of 1's you have to
9
+ * sort them in ascending order.
10
+ *
11
+ * Return the sorted array.
12
+ */
13
+
14
+ /**
15
+ * @param {number[] } arr
16
+ * @return {number[] }
17
+ */
18
+ var sortByBits = function ( arr ) {
19
+ const getCount = n => n . toString ( 2 ) . replace ( / 0 / g, '' ) . length ;
20
+
21
+ return arr . sort ( ( a , b ) => getCount ( a ) - getCount ( b ) || a - b ) ;
22
+ } ;
You can’t perform that action at this time.
0 commit comments