Skip to content

Latest commit

 

History

History
46 lines (33 loc) · 744 Bytes

0342._Power_of_Four.md

File metadata and controls

46 lines (33 loc) · 744 Bytes

342. Power of Four

难度: Easy

刷题内容

原题连接

内容描述

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?

解题方案

思路 1 - 时间复杂度: O(1)- 空间复杂度: O(1)******

recursive

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