Skip to content

Commit eff5acd

Browse files
committed
Add solution #3370
1 parent 64ef617 commit eff5acd

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2724,6 +2724,7 @@
27242724
3362|[Zero Array Transformation III](./solutions/3362-zero-array-transformation-iii.js)|Medium|
27252725
3363|[Find the Maximum Number of Fruits Collected](./solutions/3363-find-the-maximum-number-of-fruits-collected.js)|Hard|
27262726
3369|[Design an Array Statistics Tracker](./solutions/3369-design-an-array-statistics-tracker.js)|Hard|
2727+
3370|[Smallest Number With All Set Bits](./solutions/3370-smallest-number-with-all-set-bits.js)|Easy|
27272728
3372|[Maximize the Number of Target Nodes After Connecting Trees I](./solutions/3372-maximize-the-number-of-target-nodes-after-connecting-trees-i.js)|Medium|
27282729
3373|[Maximize the Number of Target Nodes After Connecting Trees II](./solutions/3373-maximize-the-number-of-target-nodes-after-connecting-trees-ii.js)|Hard|
27292730
3375|[Minimum Operations to Make Array Values Equal to K](./solutions/3375-minimum-operations-to-make-array-values-equal-to-k.js)|Easy|
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* 3370. Smallest Number With All Set Bits
3+
* https://leetcode.com/problems/smallest-number-with-all-set-bits/
4+
* Difficulty: Easy
5+
*
6+
* You are given a positive number n.
7+
*
8+
* Return the smallest number x greater than or equal to n, such that the binary
9+
* representation of x contains only set bits
10+
*/
11+
12+
/**
13+
* @param {number} n
14+
* @return {number}
15+
*/
16+
var smallestNumber = function(n) {
17+
const bits = n.toString(2).length;
18+
const result = (1 << bits) - 1;
19+
return result >= n ? result : (1 << (bits + 1)) - 1;
20+
};

0 commit comments

Comments
 (0)