public List findMaxIndices(int[] arr) { List maxIndices = new ArrayList<>(); int max = Integer.MIN_VALUE;

for (int i = 0; i < arr.length; i++) {
    if (arr[i] > max) {
        max = arr[i];
        maxIndices.clear();
        maxIndices.add(i);
    } else if (arr[i] == max) {
        maxIndices.add(i);
    }
}

return maxIndices;

}

Java 数组最大值下标查找方法

原文地址: https://www.cveoy.top/t/topic/qd9K 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录