File tree 2 files changed +34
-1
lines changed
2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,419 LeetCode solutions in JavaScript
1
+ # 1,420 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
1243
1243
1608|[ Special Array With X Elements Greater Than or Equal X] ( ./solutions/1608-special-array-with-x-elements-greater-than-or-equal-x.js ) |Easy|
1244
1244
1609|[ Even Odd Tree] ( ./solutions/1609-even-odd-tree.js ) |Medium|
1245
1245
1610|[ Maximum Number of Visible Points] ( ./solutions/1610-maximum-number-of-visible-points.js ) |Hard|
1246
+ 1611|[ Minimum One Bit Operations to Make Integers Zero] ( ./solutions/1611-minimum-one-bit-operations-to-make-integers-zero.js ) |Hard|
1246
1247
1657|[ Determine if Two Strings Are Close] ( ./solutions/1657-determine-if-two-strings-are-close.js ) |Medium|
1247
1248
1668|[ Maximum Repeating Substring] ( ./solutions/1668-maximum-repeating-substring.js ) |Easy|
1248
1249
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
+ * 1611. Minimum One Bit Operations to Make Integers Zero
3
+ * https://leetcode.com/problems/minimum-one-bit-operations-to-make-integers-zero/
4
+ * Difficulty: Hard
5
+ *
6
+ * Given an integer n, you must transform it into 0 using the following operations any number
7
+ * of times:
8
+ * - Change the rightmost (0th) bit in the binary representation of n.
9
+ * - Change the ith bit in the binary representation of n if the (i-1)th bit is set to 1 and the
10
+ * (i-2)th through 0th bits are set to 0.
11
+ *
12
+ * Return the minimum number of operations to transform n into 0.
13
+ */
14
+
15
+ /**
16
+ * @param {number } n
17
+ * @return {number }
18
+ */
19
+ var minimumOneBitOperations = function ( n ) {
20
+ if ( n === 0 ) return 0 ;
21
+
22
+ let result = 0 ;
23
+ let bit = 1 ;
24
+ while ( bit <= n ) {
25
+ if ( n & bit ) {
26
+ result = ( 1 << ( bit . toString ( 2 ) . length ) ) - 1 - result ;
27
+ }
28
+ bit <<= 1 ;
29
+ }
30
+
31
+ return result ;
32
+ } ;
You can’t perform that action at this time.
0 commit comments