A solution to power of four problem in C#


  • 0
    V

    Approach:
    Find the logarithm of the number. If it is a decimal, the original number is not a power of four.

    Here is the solution in C#.

    public class Solution {
        public bool IsPowerOfFour(int num) {
            double logr=Math.Log(num,4);
            
            return (logr%1==0);
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.