Skip to content

Commit 0f02c5c

Browse files
solves power of 2
1 parent 8ed558f commit 0f02c5c

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
| 219 | [Contains Duplicate II](https://leetcode.com/problems/contains-duplicate-ii) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ContainsDuplicateII.java) |
7070
| 225 | [Implement Stack using Queues](https://leetcode.com/problems/implement-stack-using-queues) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/MyStack.java) |
7171
| 226 | [Invert Binary Tree](https://leetcode.com/problems/invert-binary-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/InvertBinaryTree.java) |
72-
| 231 | [Power of Two](https://leetcode.com/problems/power-of-two) | Easy |
72+
| 231 | [Power of Two](https://leetcode.com/problems/power-of-two) | Easy |
7373
| 232 | [Implement Queue Using Stacks]() | Easy |
7474
| 234 | [Palindrome Linked Lists](https://leetcode.com/problems/palindrome-linked-list) | Easy |
7575
| 235 | [Lowest Common Ancestor of a Binary Search Tree](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree) | Easy |

src/PowerOf2.java

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
public class PowerOf2 {
2+
public boolean isPowerOfTwo(int number) {
3+
if (number == 1) {
4+
return true;
5+
} else if (number % 2 == 1 || number == 0) {
6+
return false;
7+
}
8+
9+
return isPowerOfTwo(number / 2);
10+
}
11+
}

0 commit comments

Comments
 (0)