Fri Nov 22 2024 12:53:59 GMT+0000 (Coordinated Universal Time)
Saved by @Narendra
class Solution { public: bool isPowerOfTwo(int n) { int count =0; if(n<0) { return 0; } while(n) { n&=n-1; count = count +1; } if(count ==1){ return 1; } else{ return 0; } } };
Copy this HTML code:
Preview:
open_in_newInstructions on embedding in Medium
Comments