DDSA
Advertisement

1780. Check if Number is a Sum of Powers of Three

1780.cs
C#
public class Solution
{
    public bool CheckPowersOfThree(int n)
    {
        while (n > 1)
        {
            int r = n % 3;
            if (r == 2)
                return false;
            n /= 3;
        }

        return true;
    }
}
Advertisement
Was this solution helpful?