码迷,mamicode.com
首页 > 其他好文 > 详细

625. Minimum Factorization

时间:2017-11-24 15:09:15      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:for   style   turn   git   signed   factor   span   class   find   

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
class Solution {
public:
    int smallestFactorization(int a) {
        if (a < 2) return a;
        string s;
        for (int i = 9; i >= 2; i--) {
            while (a % i == 0) {
                s.insert(s.begin(), (0 + i));
                a /= i;
            }
        }
        return (a > 1 || s.size() > 10 || stol(s) > INT_MAX) ? 0 : stoi(s);
    }
};

 

625. Minimum Factorization

标签:for   style   turn   git   signed   factor   span   class   find   

原文地址:http://www.cnblogs.com/jxr041100/p/7889010.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!