mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
48 lines
1.4 KiB
HTML
48 lines
1.4 KiB
HTML
<p>You are given a <em>positive</em> number <code>n</code>.</p>
|
|
|
|
<p>Return the <strong>smallest</strong> number <code>x</code> <strong>greater than</strong> or <strong>equal to</strong> <code>n</code>, such that the binary representation of <code>x</code> contains only <span data-keyword="set-bit">set bits</span></p>
|
|
|
|
<p> </p>
|
|
<p><strong class="example">Example 1:</strong></p>
|
|
|
|
<div class="example-block">
|
|
<p><strong>Input:</strong> <span class="example-io">n = 5</span></p>
|
|
|
|
<p><strong>Output:</strong> <span class="example-io">7</span></p>
|
|
|
|
<p><strong>Explanation:</strong></p>
|
|
|
|
<p>The binary representation of 7 is <code>"111"</code>.</p>
|
|
</div>
|
|
|
|
<p><strong class="example">Example 2:</strong></p>
|
|
|
|
<div class="example-block">
|
|
<p><strong>Input:</strong> <span class="example-io">n = 10</span></p>
|
|
|
|
<p><strong>Output:</strong> <span class="example-io">15</span></p>
|
|
|
|
<p><strong>Explanation:</strong></p>
|
|
|
|
<p>The binary representation of 15 is <code>"1111"</code>.</p>
|
|
</div>
|
|
|
|
<p><strong class="example">Example 3:</strong></p>
|
|
|
|
<div class="example-block">
|
|
<p><strong>Input:</strong> <span class="example-io">n = 3</span></p>
|
|
|
|
<p><strong>Output:</strong> <span class="example-io">3</span></p>
|
|
|
|
<p><strong>Explanation:</strong></p>
|
|
|
|
<p>The binary representation of 3 is <code>"11"</code>.</p>
|
|
</div>
|
|
|
|
<p> </p>
|
|
<p><strong>Constraints:</strong></p>
|
|
|
|
<ul>
|
|
<li><code>1 <= n <= 1000</code></li>
|
|
</ul>
|