Skip to content

Commit

Permalink
added PowerOfTwo.java
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Naughton Jr authored and Kevin Naughton Jr committed Jun 5, 2018
1 parent df4ee95 commit 67c261a
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 0 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file modified company/.DS_Store
Binary file not shown.
25 changes: 25 additions & 0 deletions company/google/PowerOfTwo.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Binary file modified leetcode/.DS_Store
Binary file not shown.
25 changes: 25 additions & 0 deletions leetcode/bit-manipulation/PowerOfTwo.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
25 changes: 25 additions & 0 deletions leetcode/math/PowerOfTwo.java
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 67c261a

Please sign in to comment.