1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| class Solution { public boolean isPowerOfFour(int n) { if(n <= 0){ return false; }
if(n == 1){ return true; }
int cnt = 0; while(n != 0){ if((n&1) != 0){ int tmp = n >> 1; if(tmp == 0 && cnt % 2 == 0){ return true; }else{ return false; } } n = n >> 1; cnt++; } return false; } }
|