美文网首页
计算二维数组每列的最大值

计算二维数组每列的最大值

作者: outwar | 来源:发表于2018-02-11 17:28 被阅读0次
public static int[] maxIncol(int[][] arr) {
  int[] res = arr[0];
  int[] temp;

        for (int i=1; i<arr.length; i++) {
            temp = arr[i];
            if (res.length < temp.length) {
                for (int j=0; j<res.length; j++) {
                    temp[j] = Math.max(res[j], temp[j]);
                }
                res = temp;
            } else {
                for (int j=0; j<temp.length; j++) {
                    res[j] = Math.max(res[j], temp[j]);
                }
            }
        }
  return res;
}

相关文章

网友评论

      本文标题:计算二维数组每列的最大值

      本文链接:https://www.haomeiwen.com/subject/txzktftx.html