342. Power of Four 發表於 2023-02-13 | 分類於 leetcode problemsolutionoption 112345678class Solution {public: bool isPowerOfFour(int n) { if(n<1) return false; while(n%4==0) n>>=2; return n==1; }}; option 212345678class Solution {public: bool isPowerOfFour(int n) { if(n<1) return false; if((n&(n-1))!=0) return false; return (n&0x55555555) ==n; }}; option 3 - 換底公式123456class Solution {public: bool isPowerOfFour(int n) { return (n>0 && int(log10(n)/log10(4))-log10(n)/log10(4)==0 ); }}; analysis time complexity O(1) space complexity O(1)