Skip to content

Commit c484520

Browse files
committed
693. Binary Number with Alternating Bits
1 parent 8935f2d commit c484520

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//Runtime: 3 ms
2+
class Solution {
3+
public:
4+
bool hasAlternatingBits(int n) {
5+
int c = n % 2;
6+
n /= 2;
7+
8+
while (n > 0)
9+
{
10+
if (c == n % 2)
11+
return 0;
12+
13+
c = n % 2;
14+
n /= 2;
15+
}
16+
return 1;
17+
}
18+
};

0 commit comments

Comments
 (0)