首页 > 其他 > 详细

625. Minimum Factorization

时间:2017-11-24 10:57:02      阅读:315      评论:0      收藏:0      [点我收藏+]

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!