Skip to content

Commit 62c9a59

Browse files
committed
Time: 0 ms (100%), Space: 57.8 MB (54.82%) - LeetHub
1 parent 760239a commit 62c9a59

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
function isPowerOfTwo(n: number): boolean {
22
if (n <= 0) return false;
3-
if (n === 1) return true;
4-
return n % 2 === 0 ? isPowerOfTwo(n/2) : false;
3+
4+
while (n % 2 === 0) {
5+
n /= 2;
6+
}
7+
8+
return n === 1;
59
};

0 commit comments

Comments
 (0)