[LeetCode] 625. Minimum Factorization

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[LeetCode] 625. Minimum Factorization相关的知识,希望对你有一定的参考价值。

public class Solution {
    public int smallestFactorization(int a) {
        if (a < 10) {
            return a;
        }
        List<Integer> factor = new ArrayList<>();
        for (int i = 9; i > 1; i--) {
            while (a % i == 0) {
                factor.add(i);
                a = a / i;
            }
        }
        if (a != 1) {
            return 0;
        }
        long result = 0; // otherwise, overflow
        for (int i = factor.size() - 1; i >= 0; i--) {
            result = result * 10 + factor.get(i);
            if (result > Integer.MAX_VALUE) {
                return 0;
            }
        }
        return (int)result;
    }
}

 

以上是关于[LeetCode] 625. Minimum Factorization的主要内容,如果未能解决你的问题,请参考以下文章

[leetcode-625-Minimum Factorization]

[LeetCode] 625. Minimum Factorization

LeetCode Minimum Factorization

625. Minimum Factorization

#Leetcode# 209. Minimum Size Subarray Sum

Leetcode-995 Minimum Number of K Consecutive Bit Flips(K 连续位的最小翻转次数)