package com.fishercoder.solutions;

import java.util.ArrayList;
import java.util.List;

/**
 * 625. Minimum Factorization
 *
 * 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
 */
public class _625 {

    /**reference: https://discuss.leetcode.com/topic/92854/java-solution-result-array
     * and https://leetcode.com/articles/minimum-factorization/#approach-3-using-factorizationaccepted*/
    public int smallestFactorization(int a) {
        //case 1: a < 10
        if (a < 10) {
            return a;
        }

        //case 2: start with 9 and try every possible digit
        List<Integer> resultArray = new ArrayList<>();
        for (int i = 9; i > 1; i--) {
            //if current digit divides a, then store all occurences of current digit in res
            while (a % i == 0) {
                a = a / i;
                resultArray.add(i);
            }
        }

        //if a could not be broken in form of digits, return 0
        if (a != 0) {
            return 0;
        }

        //get the result from the result array in reverse order
        long result = 0;
        for (int i = resultArray.size() - 1; i >= 0; i--) {
            result = result * 10 + resultArray.get(i);
            if (result > Integer.MAX_VALUE) {
                return 0;
            }
        }
        return (int) result;
    }

}

@@ -427,19 +427,71 @@
  %7B%0A%0A    
-/**
+public static class Solution1 %7B%0A        /**%0A         * 
 referenc
@@ -561,16 +561,20 @@
 t-array%0A
+    
      * a
@@ -671,15 +671,29 @@
 pted
-*/%0A
+%0A         */%0A   
     
+ 
 publ
@@ -734,24 +734,28 @@
 ) %7B%0A        
+    
 //case 1: a 
@@ -763,24 +763,28 @@
  10%0A        
+ 
+   
 if (a %3C 10) 
@@ -793,24 +793,28 @@
             
+   
+ 
 return a;%0A  
@@ -811,35 +811,43 @@
 turn a;%0A        
-%7D%0A%0A
+    %7D%0A%0A    
         //case 2
@@ -898,16 +898,20 @@
         
+  
+  
 List%3CInt
@@ -949,16 +949,20 @@
 st%3C%3E();%0A
+    
         
@@ -999,24 +999,28 @@
             
+    
 //if current
@@ -1099,16 +1099,20 @@
         
+  
+  
 while (a
@@ -1120,24 +1120,28 @@
 %25 i == 0) %7B%0A
+    
             
@@ -1167,24 +1167,28 @@
             
+    
 resultArray.
@@ -1207,26 +1207,33 @@
         
+ 
-%7D%0A
+   %7D%0A   
         
 %7D%0A%0A     
@@ -1216,35 +1216,40 @@
    %7D%0A           
+ 
 %7D%0A%0A
+    
         //if a c
@@ -1299,24 +1299,28 @@
 n 0%0A        
+ 
+   
 if (a != 0) 
@@ -1325,32 +1325,36 @@
 ) %7B%0A            
+    
 return 0;%0A      
@@ -1339,32 +1339,36 @@
       return 0;%0A
+    
         %7D%0A%0A     
@@ -1370,16 +1370,20 @@
         
+    
 //get th
@@ -1438,16 +1438,20 @@
         
+    
 long res
@@ -1455,24 +1455,28 @@
 result = 0;%0A
+    
         for 
@@ -1531,24 +1531,28 @@
             
+    
 result = res
@@ -1590,24 +1590,28 @@
             
+    
 if (result %3E
@@ -1640,32 +1640,36 @@
                 
+   
+ 
 return 0;%0A      
@@ -1666,32 +1666,36 @@
  0;%0A            
+    
 %7D%0A        %7D%0A    
@@ -1688,26 +1688,33 @@
         
+ 
-%7D%0A
+   %7D%0A   
         
 return (
@@ -1701,24 +1701,25 @@
 %0A           
+ 
 return (int)
@@ -1727,16 +1727,26 @@
 result;%0A
+        %7D%0A
     %7D%0A%0A%7D

refactor 625