Make FindMin more efficient (#4389)

This commit is contained in:
Lukas 2023-09-24 08:26:05 +02:00 committed by GitHub
parent d3a32135dc
commit c1476d796c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -34,10 +34,10 @@ public class FindMin {
if (array.length == 0) {
throw new IllegalArgumentException("array must be non-empty.");
}
int min = Integer.MAX_VALUE;
for (final var value : array) {
if (value < min) {
min = value;
int min = array[0];
for (int i = 1; i < array.length; i++) {
if (array[i] < min) {
min = array[i];
}
}
return min;