LeetCode Minimum Factorization

来源:互联网 发布:兼职美工如何收费 编辑:程序博客网 时间:2024/06/05 18:05
public class Solution {    int[] aa = new int[100];int j = 0;boolean flag = true;    public int smallestFactorization(int a) {smallest(a);Arrays.sort(aa);String string = "";if(j > 31 || !flag) return 0;for(int i = 0; i < 100; i++) {if(aa[i] != 0) {string = string + aa[i];}}if(string != "") {    Long temp = Long.parseLong(string);    if(temp > Integer.MAX_VALUE) {        return 0;    } else {        return Integer.parseInt(string);    }} else return 0;    }    public void smallest(int a) {if(a <= 9) {aa[j++] = a;return ; }for(int i = 9; i >=2 ; i--) {        if(a % i == 0) {        aa[j++] = i;        smallest(a/i);        return;        }        }        flag = false;return ;    }}

62

gld
原创粉丝点击