C# O(1) solution


  • -3
    A

    public int IntegerBreak(int n)
    {
    if (n == 2) return 1;
    if (n == 3) return 2;

            switch (n % 3)
            {
                case 0: return (int)Math.Pow(3, (n / 3));
                case 2: return (int)Math.Pow(3, (n - 2) / 3) * 2;
                default: return (int)Math.Pow(3, (n - 4) / 3) * 4;
            }
        }

Log in to reply
 

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