My Solution works fine and I don't know what should I correct 🙃
package pl.codegym.task.task20.task2025;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/*
Algorytmy liczbowe
*/
public class Solution {
static long bigTab[][]; //filled table with number 0-9 and their powers (createBigTab())
static byte numberTab[]; //if argument of getNumbers(370) then numberTab=[3][7][0] (createNumberTab())
static byte nSignAccount; //if argument of getNumbers(370) then nSignAccount = 3 (nSignAccount())
static List<Long> result1;
static long result[];
public static long[] getNumbers(long N) throws Exception {
result1 = new ArrayList<>();
bigTab= new long [10][20]; //max size of Long table with 0-9 and Long length (19)
createBigTab();
if(N<1) return new long[0]; // if argument is smaller than 0 then return empty table
while(N>0) {
nSignAccount = nSignAccount(N);
if (nSignAccount > 19) throw new Exception(); // if is bigger than Long then throw Exception;
createNumberTab(N);
//add number to result1 table if N = requirements
long checkNumber = 0;
for (int i = 0; i < nSignAccount; i++) {
checkNumber += bigTab[(numberTab[i])][nSignAccount];
}
if (checkNumber == N) {
result1.add(checkNumber);
}
N--;
}
//last part - add to result table and sort
Collections.sort(result1);
result = new long[result1.size()];
for(int i = 0; i < result1.size(); i ++){
result[i] = result1.get(i);
}
return result;
}
public static void createBigTab (){ //work
long q=1;
for(byte i = 0; i < 10; i ++){
for(byte j =0; j < 20; j++ ){
for(int x = 0; x<j; x++) {
q*=i;
}
if(q>Long.MAX_VALUE) continue;
if(j==0) {bigTab[i][j]=0; continue;}
bigTab[i][j] = q;
q=1;
}
}
}
public static void createNumberTab(long N){ //work
numberTab = new byte[nSignAccount];
long mnożnik=1;
for (int i = 1 ; i < nSignAccount; i ++){
mnożnik *= 10;
}
for(int i = 0; i < nSignAccount ; i ++){
numberTab[i]=(byte) (N/mnożnik);
N = N - (mnożnik*numberTab[i]);
mnożnik/=10;
}
}
public static byte nSignAccount ( long N){ //work
if(N<10) return 1;
long dzielnik = 10;
long wynik = 10;
byte signAccount=1;
while(wynik > 9){
wynik = N/dzielnik;
dzielnik*=10;
signAccount++;
}
return signAccount;
}
public static void main(String[] args) throws Exception {
long a = System.currentTimeMillis();
System.out.println(Arrays.toString(getNumbers(1000)));
long b = System.currentTimeMillis();
System.out.println("memory " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / (8 * 1024));
System.out.println("time = " + (b - a) / 1000);
a = System.currentTimeMillis();
System.out.println(Arrays.toString(getNumbers(1000000)));
b = System.currentTimeMillis();
System.out.println("memory " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / (8 * 1024));
System.out.println("time = " + (b - a) / 1000);
}
}