mirror of
https://github.com/Manoj-HV30/dsa-competitive-programming.git
synced 2026-05-16 19:35:22 +00:00
add codeforces solutions folder
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
class Solution{
|
||||
public :
|
||||
bool hasAlternatingBits(int n){
|
||||
bool cur = n%2;
|
||||
n/=2;
|
||||
while(n){
|
||||
if(n%2 == cur) return false;
|
||||
cur = n%2;
|
||||
n/=2;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
// n%2 extracts the last bit and n/=2 extracts the rest of the bits, now if last bit of the rest of the bits is equal to the current last bit, then two adjacent bits are same and hence we return false
|
||||
Reference in New Issue
Block a user