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

2018-02-11  本文已影响0人  outwar
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;
}
上一篇 下一篇

猜你喜欢

热点阅读