C++ simple and short solution


  • 0
    M
    int smallestFactorization(int a) {
            if(a<10) return a;
            vector<int> res;
            long num=0, mul=1;
            for(int i=9;i>1;i--) {
                while(a%i==0) {
                    a/=i;
                    res.push_back(i);
                }
            }
            if(a>9||res.size()>10) return 0;
            sort(res.begin(), res.end());
            for(int i=res.size()-1;i>=0;i--) {
                num+=res[i]*mul;
                mul*=10;
            }
            if(num>INT_MAX) return 0;
            return num;
        }

Log in to reply
 

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