安全问答

安全问答是一个知识全球问答,包含丰富的问答知识

首页 常规 游戏 娱乐 科技 程序员

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

  • 日期: 2025-09-05
  • 标签: 常规

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点我,无需注册和登录

  • 上一篇: WordPress Query: Combining 'in_stock' and 'sortby' Conditions
  • 下一篇: React.js 按钮点击前登录状态检查:避免未登录调用 API

© 2019 • 2025 - 安全问答 站长邮箱:wxgpt@qq.com    ICP备案/许可证号:鲁ICP备2026057792号