-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2 的幂 [power-of-two].html
54 lines (37 loc) · 1.17 KB
/
2 的幂 [power-of-two].html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<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>