#Leetcode# 342. Power of Four

https://leetcode.com/problems/power-of-four/

Given an integer (signed 32 bits), write a function to check whether it is a power of 4.

Example 1:

Input: 16
Output: true

Example 2:

Input: 5
Output: false

代码 :

class Solution {
public:
    bool isPowerOfFour(int num) {
        while(num && (num % 4) == 0)
            num /= 4;
        
        if(num == 1) return true;
        return false;
    }
};

  

原文地址:https://www.cnblogs.com/zlrrrr/p/9992296.html