Easy recursive solution


  • 0
    J
    public class Solution {
        public int smallestFactorization(int a) {
            if (a < 10) {
                return a;
            }
            
            for (int i = 9; i >= 2; i--) {
                if (a % i == 0) {
                    int pre = smallestFactorization(a / i);
                    if (pre != 0) {
                        int ans = 0;
                        try {
                            ans = Integer.parseInt(pre + "" + i);
                            return ans;
                        } catch (Exception ex) {
                            continue;
                        }
                    }
                }
            }
            return 0;
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.