描述:给出整数 n, 返回一个大小为 n * n 的螺旋矩阵
给出 n = 3
则螺旋矩阵为:
[ [1,2,3],[8,9,4],[7,6,5] ]
```
public classSolution{
public int[][] spiralArray(int n) {
int[][] res = new int[n][n];
int[] dx = new int[]{0, 1, 0, -1};
int[] dy = new int[]{1, 0, -1, 0};
int x, y, d;
int i, j, nx, ny;
```
public classSolution{public int[][] spiralArray(int n)
{
int[][] res = new int[n][n];
int[] dx = new int[]{0, 1, 0, -1};
int[] dy = new int[]{1, 0, -1, 0};
int x, y, d;
int i, j, nx, ny;
网友评论