1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/2 的幂 [power-of-two].html
2022-03-29 12:43:11 +08:00

55 lines
1.2 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你一个整数 <code>n</code>,请你判断该整数是否是 2 的幂次方。如果是,返回 <code>true</code> ;否则,返回 <code>false</code></p>
<p>如果存在一个整数 <code>x</code> 使得 <code>n == 2<sup>x</sup></code> ,则认为 <code>n</code> 是 2 的幂次方。</p>
<p> </p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>n = 1
<strong>输出:</strong>true
<strong>解释:</strong>2<sup>0</sup> = 1
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>n = 16
<strong>输出:</strong>true
<strong>解释:</strong>2<sup>4</sup> = 16
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>n = 3
<strong>输出:</strong>false
</pre>
<p><strong>示例 4</strong></p>
<pre>
<strong>输入:</strong>n = 4
<strong>输出:</strong>true
</pre>
<p><strong>示例 5</strong></p>
<pre>
<strong>输入:</strong>n = 5
<strong>输出:</strong>false
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>-2<sup>31</sup> <= n <= 2<sup>31</sup> - 1</code></li>
</ul>
<p> </p>
<p><strong>进阶:</strong>你能够不使用循环/递归解决此问题吗?</p>