小米杨辉三角内存超限,求解
static long fun(long x) {
int[][] a = new int[(int) (x+1)][];
for(int i = 0 ; i < x+1 ; i++){
a[i] = new int[i+1];
for(int j = 0 ; j < a[i].length ; j++){
a[i][j] = 1;
}
}
for(int i = 1 ; i < x+1 ; i++){
for(int j = 1 ; j < a[i].length-1 ; j++){
a[i][j] = a[i-1][j-1] + a[i-1][j];
if(a[i][j] == x){
//System.out.println(" "+(i+1));
return i+1;
}
}
}
return x;
}
#小米#
int[][] a = new int[(int) (x+1)][];
for(int i = 0 ; i < x+1 ; i++){
a[i] = new int[i+1];
for(int j = 0 ; j < a[i].length ; j++){
a[i][j] = 1;
}
}
for(int i = 1 ; i < x+1 ; i++){
for(int j = 1 ; j < a[i].length-1 ; j++){
a[i][j] = a[i-1][j-1] + a[i-1][j];
if(a[i][j] == x){
//System.out.println(" "+(i+1));
return i+1;
}
}
}
return x;
}
#小米#