Minimum Factorization

来源:互联网 发布:婚礼 简单 知乎 编辑:程序博客网 时间:2024/06/01 08:46


Given a positive integer a, find the smallest positive integer b whose multiplication of each digit equals to a.

If there is no answer or the answer is not fit in 32-bit signed integer, then return 0.

Example 1
Input:

48 
Output:
68

Example 2
Input:

15
Output:
35
Solution:
class Solution {public:    int smallestFactorization(int a) {        if(a<10)return a;        vector<int> tmp;        for(int i=9;i>1;i--)             while(a%i==0) {                a = a/ i;                tmp.push_back(i);            }        if(a>10)  return  0;        long long ret =0;        for(int i =tmp.size()-1;i>=0;i--) {            ret = ret*10+tmp[i];            if(ret>2147483647) return 0;        }              return ret;    }};

原创粉丝点击