Concise c++ solution, 10 lines, 3ms


  • 0
    int smallestFactorization(int a) {
        if (a < 10) return a;
        long res = 0;
        for (long i = 9, f = 1; i > 1; i--)
            while (a % i == 0) {
                res += i * f;
                if (res > INT_MAX) return 0;
                a /= i;
                f *= 10;
            }
        return a == 1 ? res : 0;
    }
    

Log in to reply
 

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