1. Description
Implement pow(x, n).
2. Runtime Distribution
3. Submission Details
4. Example
Input 16
Output: True
5. Code
[restabs alignment="osc-tabs-right" responsive="true" icon="true" text="More" seltabcolor="#fdfdfd" seltabheadcolor="#000" tabheadcolor="blue"]
[restab title="Java" active="active"]
public boolean isPowerOfTwo(int n) { long num = n; if (n == 0) { return false; } return (num & (num - 1)) == 0; }
[/restab]
[/restabs]
6.Test
[restabs alignment="osc-tabs-right" responsive="true" icon="true" text="More" seltabcolor="#fdfdfd" seltabheadcolor="#000" tabheadcolor="blue"]
[restab title="Java" active="active" ]
public class LeetCode0231 { public boolean isPowerOfTwo(int n) { long num = n; if (n == 0) { return false; } return (num & (num - 1)) == 0; } public static void main(String[] args) { LeetCode0231 leetcode = new LeetCode0231(); System.out.println(leetcode.isPowerOfTwo(256)); } }
[/restab]
[/restabs]
Comments | NOTHING