Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 365ba17

Browse files
committedApr 22, 2025
Add solution #1611
1 parent 7a1c4cd commit 365ba17

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed
 

‎README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,419 LeetCode solutions in JavaScript
1+
# 1,420 LeetCode solutions in JavaScript
22

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

@@ -1243,6 +1243,7 @@
12431243
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|
12441244
1609|[Even Odd Tree](./solutions/1609-even-odd-tree.js)|Medium|
12451245
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|
12461247
1657|[Determine if Two Strings Are Close](./solutions/1657-determine-if-two-strings-are-close.js)|Medium|
12471248
1668|[Maximum Repeating Substring](./solutions/1668-maximum-repeating-substring.js)|Easy|
12481249
1669|[Merge In Between Linked Lists](./solutions/1669-merge-in-between-linked-lists.js)|Medium|
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
};

0 commit comments

Comments
 (0)
Please sign in to comment.