#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;
    }
};

  

posted @ 2018-11-20 22:45  丧心病狂工科女  阅读(88)  评论(0编辑  收藏  举报