So it's work on my laptop,
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407]
memory 248 kB
time = 23 ms
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407, 1634, 6688, 8208, 9474, 33286, 54748, 91818, 91819, 92727, 93084, 117651, 548834]
memory 379 kB
time = 858 ms
but still show me that is too long, and colapse Validation
it's no perfect code
package pl.codegym.task.task20.task2025;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/*
Algorytmy liczbowe
*/
public class Solution {
public static long[] getNumbers(long N) {
List<Long> list = new ArrayList<>();
for (long x = 0, z = 0; x < N; x++) {
long temp = 1L;
long temp2 = 0L;
String[] strings = Long.toString(x).split("");
for (int y = 0; y < strings.length; y++) {
temp = 1L;
for (int p = 0; p < strings.length; p++) {
if (strings[y].equals("0")) {
temp = 0L;
break;
} else {
temp *= Long.parseLong(strings[y]);
}
}
temp2 += temp;
if (x == temp2) {
if (list.contains(temp2)) break;
list.add(temp2);
z++;
}
}
}
long[] result = list.stream().mapToLong(i -> i).toArray();
return result;
}
public static void main(String[] args) {
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);
}
}