it grabs the correct Armstrong numbers when you run it, but times out on verification.
[1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407]
memory 512
time = 0
[1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407, 1634, 8208, 9474, 54748, 92727, 93084, 548834]
memory 19184
time = 0
package com.codegym.task.task20.task2025;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/*
Number algorithms
*/
public class Solution {
public static long[] getNumbers(long N) {
List<Long> longsList = new ArrayList<>();
for (long i = N; i > 0; i--) {
long S = 0;
String strNum = Long.toString(i);
int M = strNum.length();
String[] longArray = strNum.split("(?<=\\d)");
for (String x : longArray) {
S += (long) Math.pow(Double.parseDouble(x), M);
}
if (S == i) {
longsList.add(S);
}
}
Collections.sort(longsList);
return longsList.stream().mapToLong(Long::longValue).toArray();
}
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);
}
}