diff --git a/.DS_Store b/.DS_Store index 034b6c2..74bb090 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/company/.DS_Store b/company/.DS_Store index 2eef6b9..70ad936 100644 Binary files a/company/.DS_Store and b/company/.DS_Store differ diff --git a/company/google/PowerOfTwo.java b/company/google/PowerOfTwo.java new file mode 100644 index 0000000..793a00a --- /dev/null +++ b/company/google/PowerOfTwo.java @@ -0,0 +1,25 @@ +//Given an integer, write a function to determine if it is a power of two. +// +//Example 1: +// +//Input: 1 +//Output: true +//Example 2: +// +//Input: 16 +//Output: true +//Example 3: +// +//Input: 218 +//Output: false + +class PowerOfTwo { + public boolean isPowerOfTwo(int n) { + long i = 1; + while(i < n) { + i <<= 1; + } + + return i == n; + } +} diff --git a/leetcode/.DS_Store b/leetcode/.DS_Store index f6bd90e..137d841 100644 Binary files a/leetcode/.DS_Store and b/leetcode/.DS_Store differ diff --git a/leetcode/bit-manipulation/PowerOfTwo.java b/leetcode/bit-manipulation/PowerOfTwo.java new file mode 100644 index 0000000..793a00a --- /dev/null +++ b/leetcode/bit-manipulation/PowerOfTwo.java @@ -0,0 +1,25 @@ +//Given an integer, write a function to determine if it is a power of two. +// +//Example 1: +// +//Input: 1 +//Output: true +//Example 2: +// +//Input: 16 +//Output: true +//Example 3: +// +//Input: 218 +//Output: false + +class PowerOfTwo { + public boolean isPowerOfTwo(int n) { + long i = 1; + while(i < n) { + i <<= 1; + } + + return i == n; + } +} diff --git a/leetcode/math/PowerOfTwo.java b/leetcode/math/PowerOfTwo.java new file mode 100644 index 0000000..793a00a --- /dev/null +++ b/leetcode/math/PowerOfTwo.java @@ -0,0 +1,25 @@ +//Given an integer, write a function to determine if it is a power of two. +// +//Example 1: +// +//Input: 1 +//Output: true +//Example 2: +// +//Input: 16 +//Output: true +//Example 3: +// +//Input: 218 +//Output: false + +class PowerOfTwo { + public boolean isPowerOfTwo(int n) { + long i = 1; + while(i < n) { + i <<= 1; + } + + return i == n; + } +}