Java 算法:查找数组中最后一个最小值的索引
public class Main {
public static void main(String[] args) {
int[] L = {1, 5, 1, 1, 3, 2, 4};
int lastMinIndex = findLastMinIndex(L);
System.out.println(lastMinIndex);
}
public static int findLastMinIndex(int[] L) {
int min = L[0];
int lastMinIndex = 0;
for (int i = 1; i < L.length; i++) {
if (L[i] <= min) {
min = L[i];
lastMinIndex = i;
}
}
return lastMinIndex;
}
}
原文地址: https://www.cveoy.top/t/topic/pgTl 著作权归作者所有。请勿转载和采集!