Simple C# Beginner Solution


  • 0
    I

    Simple for beginners to understand. 2^31 is roughly max int, so Math.Pow checks to see if 2 to the power of every number from 0-31 is equal to n.

            for (int i = 0; i <= 31; i++)
            {
                if (Math.Pow(2,i)==n)
                {
                    return true;
                }
            }
            return false;
    

Log in to reply
 

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