LeetCode 0625. Minimum Factorization Solution in Java, C++, Python & Go | Explanation + Code

CoderIndeed
0
0625. Minimum Factorization

Description

Given a positive integer num, return the smallest positive integer x whose multiplication of each digit equals num. If there is no answer or the answer is not fit in 32-bit signed integer, return 0.

 

Example 1:

Input: num = 48
Output: 68

Example 2:

Input: num = 15
Output: 35

 

Constraints:

  • 1 <= num <= 231 - 1

Solutions

Solution 1

PythonJavaC++Go
class Solution: def smallestFactorization(self, num: int) -> int: if num < 2: return num ans, mul = 0, 1 for i in range(9, 1, -1): while num % i == 0: num //= i ans = mul * i + ans mul *= 10 return ans if num < 2 and ans <= 2**31 - 1 else 0(code-box)

Post a Comment

0Comments

Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Check Now
Accept !