解题思路:
class Solution {
public int[] spiralArray(int[][] array) {
if(array.length == 0) return new int[0];
int l = 0, r = array[0].length - 1;
int t = 0, b = array.length - 1;
int x = 0;
int[] res = new int[(r + 1) * (b + 1)];
while(true) {
for(int i = l; i <= r; i++) res[x++] = array[t][i]; //从左到右
if(++t > b) break;
for(int i = t; i <= b; i++) res[x++] = array[i][r]; //从上到下
if(--r < l) break;
for(int i = r; i >= l; i--) res[x++] = array[b][i]; //从右到左
if(--b < t) break;
for(int i = b; i >= t; i--) res[x++] = array[i][l]; //从下到上
if(++l > r) break;
}
return res;
}
}