Package g0201_0300.s0231_power_of_two
Class Solution
-
- All Implemented Interfaces:
public final class Solution231 - Power of Two.
Easy
Given an integer
n, returntrueif it is a power of two. Otherwise, returnfalse.An integer
nis a power of two, if there exists an integerxsuch that <code>n == 2<sup>x</sup></code>.Example 1:
Input: n = 1
Output: true
Explanation: 2<sup>0</sup> = 1
Example 2:
Input: n = 16
Output: true
Explanation: 2<sup>4</sup> = 16
Example 3:
Input: n = 3
Output: false
Constraints:
<code>-2<sup>31</sup><= n <= 2<sup>31</sup> - 1</code>
Follow up: Could you solve it without loops/recursion?
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final BooleanisPowerOfTwo(Integer n)-
-
Method Detail
-
isPowerOfTwo
final Boolean isPowerOfTwo(Integer n)
-
-
-
-