Skip to content

Latest commit

 

History

History
27 lines (25 loc) · 571 Bytes

File metadata and controls

27 lines (25 loc) · 571 Bytes

🔮 Question

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
Follow up: Could you solve it without loops/recursion?

🐉 Solution

class Solution {
    public boolean isPowerOfFour(int num) {
        while(num>0){
            if(num==1)
                return true;
            if(num%4!=0)
                return false;
            else
                num/=4;
        }
        return false;
    }
}