题解 | #二维数组打印#

二维数组打印

http://www.nowcoder.com/practice/6fadc1dac83a443c9434f350a5803b51

解题思路:两层循环,外层循环控制次数,内层循环负责向数组中写入数据

import java.util.*;

public class Printer {
    public int[] arrayPrint(int[][] arr, int n) {
        // write code here
        int[] res = new int[n * n];
        int index = 0;
        for (int j = n - 1; j >= 0; j--) {
            for (int i = 0; i < n - j; i++) {
                res[index] = arr[i][j + i];
                res[n * n - 1 - index] = arr[n - 1 - i][n - 1 - j - i];
                index++;
            }
        }
        return res;
    }
}
全部评论

相关推荐

青春运维少年不会梦到...:实习大王
点赞 评论 收藏
分享
09-17 19:25
已编辑
太原理工大学 游戏测试
叁六玖:公司名发我,我要这个HR带我打瓦
我的秋招日记
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务