File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change 56
56
151|[ Reverse Words in a String] ( ./0151-reverse-words-in-a-string.js ) |Medium|
57
57
152|[ Maximum Product Subarray] ( ./0152-maximum-product-subarray.js ) |Medium|
58
58
179|[ Largest Number] ( ./0179-largest-number.js ) |Medium|
59
+ 191|[ Number of 1 Bits] ( ./0191-number-of-1-bits.js ) |Easy|
59
60
203|[ Remove Linked List Elements] ( ./0203-remove-linked-list-elements.js ) |Easy|
60
61
206|[ Reverse Linked List] ( ./0206-reverse-linked-list.js ) |Easy|
61
62
217|[ Contains Duplicate] ( ./0217-contains-duplicate.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 191. Number of 1 Bits
3
+ * https://leetcode.com/problems/number-of-1-bits/
4
+ * Difficulty: Easy
5
+ *
6
+ * Write a function that takes an unsigned integer and returns the number of
7
+ * '1' bits it has (also known as the Hamming weight).
8
+ */
9
+
10
+ /**
11
+ * @param {number } n - a positive integer
12
+ * @return {number }
13
+ */
14
+ var hammingWeight = function ( n ) {
15
+ return n . toString ( 2 ) . match ( / 1 / g) ?. length || 0 ;
16
+ } ;
You can’t perform that action at this time.
0 commit comments