Power of Two Check
JavaScript
Easy
2 views
Problem Description
Given an integer n, print YES if it is a power of 2, else print NO. Use bit logic, not loops.
Input Format
One integer n.
Constraints
n is a 32-bit signed integer.
Official Solution
const fs=require('fs');const s=fs.readFileSync(0,'utf8').trim();if(!s){process.exit(0);}const n=Number(s);const ok=n>0 && (n & (n-1))===0;process.stdout.write(ok?'YES':'NO');
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!