Package g0201_0300.s0231_power_of_two
Class Solution
java.lang.Object
g0201_0300.s0231_power_of_two.Solution
231 - Power of Two.<p>Easy</p>
<p>Given an integer <code>n</code>, return <em><code>true</code> if it is a power of two. Otherwise, return <code>false</code></em>.</p>
<p>An integer <code>n</code> is a power of two, if there exists an integer <code>x</code> such that <code>n == 2<sup>x</sup></code>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> n = 1</p>
<p><strong>Output:</strong> true</p>
<p><strong>Explanation:</strong> 2<sup>0</sup> = 1</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> n = 16</p>
<p><strong>Output:</strong> true</p>
<p><strong>Explanation:</strong> 2<sup>4</sup> = 16</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> n = 3</p>
<p><strong>Output:</strong> false</p>
<p><strong>Example 4:</strong></p>
<p><strong>Input:</strong> n = 4</p>
<p><strong>Output:</strong> true</p>
<p><strong>Example 5:</strong></p>
<p><strong>Input:</strong> n = 5</p>
<p><strong>Output:</strong> false</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>-2<sup>31</sup> <= n <= 2<sup>31</sup> - 1</code></li>
</ul>
<p><strong>Follow up:</strong> Could you solve it without loops/recursion?</p>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
isPowerOfTwo
public boolean isPowerOfTwo(int n)
-