解题思路:两层循环,外层循环控制次数,内层循环负责向数组中写入数据
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;
}
}